Add remaining type aliases, rewrite settings tab as syntax TL;DR

- Add age (birthday), remaining (countdown), elapsed (since) aliases,
  alongside the existing bday/until/difference.
- README: document new aliases in each type's header and the Type
  Aliases section.
- Settings tab rewritten: drop the stale GitHub doc link and hardcoded
  pre-redesign examples (countdown+from, auto-colon labels). Replace
  with a compact syntax TL;DR \u2014 all four types with their aliases,
  fields, and one-line descriptions, plus relative dates, frontmatter
  fallback, and inline/fenced examples \u2014 and link to the README on
  Gitea (was pointing at a stale GitHub URL).

Verified: aliases tested against the real shipped config parser; the
settings tab's actual display() (found via app.setting.pluginTabs) was
invoked live in Obsidian and rendered exactly the intended content with
no errors.
This commit is contained in:
2026-09-07 12:09:55 -04:00
parent 68e7b3ab04
commit 537198c4f1
3 changed files with 70 additions and 45 deletions
+60 -37
View File
@@ -1,6 +1,8 @@
import { App, PluginSettingTab, Setting } from "obsidian";
import type DateCalcPlugin from "../main";
const README_URL = "https://gitea.mithrilforge.dev/olivier/date-calculator";
export class DateCalcSettingTab extends PluginSettingTab {
constructor(app: App, private plugin: DateCalcPlugin) {
super(app, plugin);
@@ -12,14 +14,10 @@ export class DateCalcSettingTab extends PluginSettingTab {
containerEl.createEl("h2", { text: "Date Calc" });
// Documentation link
const docsDiv = containerEl.createDiv({
cls: "setting-item-description date-calc-settings-docs",
});
docsDiv.createEl("a", {
text: "📖 View Full Documentation",
href: "https://github.com/thelegend09/date-calculator",
});
docsDiv.createEl("a", { text: "📖 Full syntax reference (README)", href: README_URL });
new Setting(containerEl)
.setName("Debug logging")
@@ -53,43 +51,68 @@ export class DateCalcSettingTab extends PluginSettingTab {
})
);
// Usage examples section
containerEl.createEl("h3", { text: "Usage Examples" });
containerEl.createEl("h3", { text: "Syntax at a glance" });
const tldr = containerEl.createDiv({ cls: "date-calc-examples" });
const examplesDiv = containerEl.createDiv({ cls: "date-calc-examples" });
tldr.createEl("p", {
text: "Use `date-calc: ...` inline, or a fenced ```date-calc block with type: set explicitly (or inferred from which fields you give).",
});
// Inline examples
examplesDiv.createEl("h4", { text: "Inline Code (single backticks)" });
const inlineList = examplesDiv.createEl("ul");
inlineList.createEl("li").setText("`date-calc: birthday=2003-02-15`");
inlineList.createEl("li").setText("`date-calc: countdown to=2026-12-31 label=\"New Year\"`");
inlineList.createEl("li").setText("`date-calc: since=2024-01-01`");
inlineList.createEl("li").setText("`date-calc: diff from=2024-01-01 to=2024-12-31`");
inlineList.createEl("li").setText("`date-calc: birthday=1992-08-16 verbose=true`");
// Types table
const typesList = tldr.createEl("ul");
const addType = (name: string, aliases: string, desc: string, fields: string) => {
const li = typesList.createEl("li");
li.createEl("strong", { text: name });
li.appendText(` (${aliases}) — ${desc} `);
li.createEl("br");
li.createEl("code", { text: fields });
};
addType(
"birthday", "bday, age",
"age + days until next birthday.",
"birthday/birthdate/date, label"
);
addType(
"countdown", "until, remaining",
"time until a date, always from now.",
"to/until/date, label"
);
addType(
"since", "elapsed",
"time since a date, always from now.",
"since/from/date"
);
addType(
"diff", "difference",
"time between two fixed dates (neither has to be now).",
"from/start, to/end"
);
// Block examples
examplesDiv.createEl("h4", { text: "Fenced Blocks (triple backticks)" });
tldr.createEl("h4", { text: "Relative dates" });
tldr.createEl("p", {
text: "today, now, tomorrow, yesterday, or an offset like +7d / -3mo / +2w (always relative to now).",
});
examplesDiv
tldr.createEl("h4", { text: "Frontmatter fallback" });
tldr.createEl("p", {
text: "Every type reads its date(s) from frontmatter if not given inline: birthday/birthdate, to/deadline, since/created, from/start + to/end.",
});
tldr.createEl("h4", { text: "Examples" });
const examplesList = tldr.createEl("ul");
examplesList.createEl("li").createEl("code", { text: "date-calc: birthday=1992-08-16" });
examplesList.createEl("li").createEl("code", { text: "date-calc: to=2026-12-31 label=\"New Year:\"" });
examplesList.createEl("li").createEl("code", { text: "date-calc: since=2024-01-01" });
examplesList.createEl("li").createEl("code", { text: "date-calc: from=2024-01-01 to=today" });
examplesList
.createEl("li")
.createEl("pre", { cls: "date-calc-example-block" })
.setText("```date-calc\ntype: birthday\nbirthday: 1992-08-16\n```");
.setText("```date-calc\ntype: countdown\nto: +30d\nlabel: \"Sprint:\"\nverbose: true\n```");
examplesDiv
.createEl("pre", { cls: "date-calc-example-block" })
.setText(
"```date-calc\ntype: countdown\nto: 2026-12-31 23:59\nlabel: New Year\nverbose: true\n```"
);
examplesDiv
.createEl("pre", { cls: "date-calc-example-block" })
.setText("```date-calc\ntype: diff\nfrom: 2024-01-01\nto: 2024-12-31\n```");
// Tips section
examplesDiv.createEl("h4", { text: "Tips" });
const tipsList = examplesDiv.createEl("ul");
tipsList.createEl("li").setText("Use YYYY-MM-DD format for dates");
tipsList.createEl("li").setText("Add time with YYYY-MM-DD HH:mm for precise countdowns");
tipsList.createEl("li").setText("Supported types: birthday, countdown, since, diff");
tipsList.createEl("li").setText("Add verbose=true/false to override global setting");
const fullDocs = tldr.createEl("p");
fullDocs.appendText("Full field reference, custom styling, and more examples: ");
fullDocs.createEl("a", { text: "README on Gitea", href: README_URL });
fullDocs.appendText(".");
}
}