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:
@@ -21,7 +21,7 @@ Use inline code for quick calculations: `date-calc: birthday=1992-08-16`
|
|||||||
|
|
||||||
## Supported Calculation Types
|
## Supported Calculation Types
|
||||||
|
|
||||||
### Birthday (`birthday`)
|
### Birthday (`birthday`, `bday`, `age`)
|
||||||
|
|
||||||
Calculates age and time until next birthday.
|
Calculates age and time until next birthday.
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ birthday: 2000-05-21
|
|||||||
label: "John's age:"
|
label: "John's age:"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Countdown (`countdown` or `until`)
|
### Countdown (`countdown`, `until`, `remaining`)
|
||||||
|
|
||||||
Time remaining until a target date, **always measured from now**. For a comparison between two fixed dates, use `diff` instead.
|
Time remaining until a target date, **always measured from now**. For a comparison between two fixed dates, use `diff` instead.
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ label: "New Year:"
|
|||||||
to: 2025-12-31 23:59
|
to: 2025-12-31 23:59
|
||||||
```
|
```
|
||||||
|
|
||||||
### Since (`since`)
|
### Since (`since`, `elapsed`)
|
||||||
|
|
||||||
Time elapsed since an event (or time until, if the event is in the future) — always measured against now.
|
Time elapsed since an event (or time until, if the event is in the future) — always measured against now.
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ type: since
|
|||||||
since: 2024-12-20
|
since: 2024-12-20
|
||||||
```
|
```
|
||||||
|
|
||||||
### Difference (`diff`)
|
### Difference (`diff`, `difference`)
|
||||||
|
|
||||||
The time difference between two fixed dates — neither has to be "now". For a countdown relative to the present moment, use `countdown` instead.
|
The time difference between two fixed dates — neither has to be "now". For a countdown relative to the present moment, use `countdown` instead.
|
||||||
|
|
||||||
@@ -187,8 +187,9 @@ Settings → "Hide result while cursor inside" prevents rendered output from sho
|
|||||||
|
|
||||||
For convenience, use these shortcuts:
|
For convenience, use these shortcuts:
|
||||||
|
|
||||||
- `birthday` = `bday`
|
- `birthday` = `bday` = `age`
|
||||||
- `countdown` = `until`
|
- `countdown` = `until` = `remaining`
|
||||||
|
- `since` = `elapsed`
|
||||||
- `diff` = `difference`
|
- `diff` = `difference`
|
||||||
|
|
||||||
## Custom Styling
|
## Custom Styling
|
||||||
|
|||||||
+3
-2
@@ -87,9 +87,10 @@ export function normalizeConfig(
|
|||||||
else if (resolved.since || resolved.from) type = "since";
|
else if (resolved.since || resolved.from) type = "since";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "bday") type = "birthday";
|
if (type === "bday" || type === "age") type = "birthday";
|
||||||
if (type === "until") type = "countdown";
|
if (type === "until" || type === "remaining") type = "countdown";
|
||||||
if (type === "difference") type = "diff";
|
if (type === "difference") type = "diff";
|
||||||
|
if (type === "elapsed") type = "since";
|
||||||
|
|
||||||
return { type, cfg: resolved };
|
return { type, cfg: resolved };
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-37
@@ -1,6 +1,8 @@
|
|||||||
import { App, PluginSettingTab, Setting } from "obsidian";
|
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||||
import type DateCalcPlugin from "../main";
|
import type DateCalcPlugin from "../main";
|
||||||
|
|
||||||
|
const README_URL = "https://gitea.mithrilforge.dev/olivier/date-calculator";
|
||||||
|
|
||||||
export class DateCalcSettingTab extends PluginSettingTab {
|
export class DateCalcSettingTab extends PluginSettingTab {
|
||||||
constructor(app: App, private plugin: DateCalcPlugin) {
|
constructor(app: App, private plugin: DateCalcPlugin) {
|
||||||
super(app, plugin);
|
super(app, plugin);
|
||||||
@@ -12,14 +14,10 @@ export class DateCalcSettingTab extends PluginSettingTab {
|
|||||||
|
|
||||||
containerEl.createEl("h2", { text: "Date Calc" });
|
containerEl.createEl("h2", { text: "Date Calc" });
|
||||||
|
|
||||||
// Documentation link
|
|
||||||
const docsDiv = containerEl.createDiv({
|
const docsDiv = containerEl.createDiv({
|
||||||
cls: "setting-item-description date-calc-settings-docs",
|
cls: "setting-item-description date-calc-settings-docs",
|
||||||
});
|
});
|
||||||
docsDiv.createEl("a", {
|
docsDiv.createEl("a", { text: "📖 Full syntax reference (README)", href: README_URL });
|
||||||
text: "📖 View Full Documentation",
|
|
||||||
href: "https://github.com/thelegend09/date-calculator",
|
|
||||||
});
|
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName("Debug logging")
|
.setName("Debug logging")
|
||||||
@@ -53,43 +51,68 @@ export class DateCalcSettingTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Usage examples section
|
containerEl.createEl("h3", { text: "Syntax at a glance" });
|
||||||
containerEl.createEl("h3", { text: "Usage Examples" });
|
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
|
// Types table
|
||||||
examplesDiv.createEl("h4", { text: "Inline Code (single backticks)" });
|
const typesList = tldr.createEl("ul");
|
||||||
const inlineList = examplesDiv.createEl("ul");
|
const addType = (name: string, aliases: string, desc: string, fields: string) => {
|
||||||
inlineList.createEl("li").setText("`date-calc: birthday=2003-02-15`");
|
const li = typesList.createEl("li");
|
||||||
inlineList.createEl("li").setText("`date-calc: countdown to=2026-12-31 label=\"New Year\"`");
|
li.createEl("strong", { text: name });
|
||||||
inlineList.createEl("li").setText("`date-calc: since=2024-01-01`");
|
li.appendText(` (${aliases}) — ${desc} `);
|
||||||
inlineList.createEl("li").setText("`date-calc: diff from=2024-01-01 to=2024-12-31`");
|
li.createEl("br");
|
||||||
inlineList.createEl("li").setText("`date-calc: birthday=1992-08-16 verbose=true`");
|
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
|
tldr.createEl("h4", { text: "Relative dates" });
|
||||||
examplesDiv.createEl("h4", { text: "Fenced Blocks (triple backticks)" });
|
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" })
|
.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
|
const fullDocs = tldr.createEl("p");
|
||||||
.createEl("pre", { cls: "date-calc-example-block" })
|
fullDocs.appendText("Full field reference, custom styling, and more examples: ");
|
||||||
.setText(
|
fullDocs.createEl("a", { text: "README on Gitea", href: README_URL });
|
||||||
"```date-calc\ntype: countdown\nto: 2026-12-31 23:59\nlabel: New Year\nverbose: true\n```"
|
fullDocs.appendText(".");
|
||||||
);
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user