Add period note commands with hotkeys and next/prev navigation

- Add 5 'Go to' commands with default hotkeys:
  Ctrl+Shift+Alt+D/W/M/Q/Y for daily/weekly/monthly/quarterly/yearly
- Add 10 navigation commands (next/prev) for each period type
- Add detectPeriodType() and navigatePeriodNote() helpers
- Bump version to 1.1.0
This commit is contained in:
2026-06-08 12:32:21 -04:00
parent fbdc42b4a3
commit a4714f6fa8
4 changed files with 133 additions and 13 deletions
+9 -9
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,7 +1,7 @@
{
"id": "waypoint",
"name": "Waypoint",
"version": "1.0.0",
"version": "1.1.0",
"minAppVersion": "0.16.3",
"description": "Calendar, recent files, and custom bookmarks sidebar.",
"author": "Olivier",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "waypoint",
"version": "1.0.0",
"version": "1.1.0",
"description": "Calendar, recent files, and custom bookmarks sidebar.",
"main": "main.js",
"scripts": {
+122 -2
View File
@@ -78,13 +78,70 @@ export default class WaypointPlugin extends Plugin {
});
this.addCommand({
id: 'waypoint-go-to-today',
name: 'Go to today\'s daily note',
id: 'waypoint-go-to-daily',
name: 'Go to daily note',
hotkeys: [{ modifiers: ['Mod', 'Shift', 'Alt'], key: 'd' }],
callback: async () => {
await this.openPeriodNote('day', moment());
},
});
this.addCommand({
id: 'waypoint-go-to-weekly',
name: 'Go to weekly note',
hotkeys: [{ modifiers: ['Mod', 'Shift', 'Alt'], key: 'w' }],
callback: async () => {
await this.openPeriodNote('week', moment());
},
});
this.addCommand({
id: 'waypoint-go-to-monthly',
name: 'Go to monthly note',
hotkeys: [{ modifiers: ['Mod', 'Shift', 'Alt'], key: 'm' }],
callback: async () => {
await this.openPeriodNote('month', moment());
},
});
this.addCommand({
id: 'waypoint-go-to-quarterly',
name: 'Go to quarterly note',
hotkeys: [{ modifiers: ['Mod', 'Shift', 'Alt'], key: 'q' }],
callback: async () => {
await this.openPeriodNote('quarter', moment());
},
});
this.addCommand({
id: 'waypoint-go-to-yearly',
name: 'Go to yearly note',
hotkeys: [{ modifiers: ['Mod', 'Shift', 'Alt'], key: 'y' }],
callback: async () => {
await this.openPeriodNote('year', moment());
},
});
// ── Period navigation commands (no hotkeys) ──
const directions = ['next', 'prev'] as const;
const periodLabels = ['daily', 'weekly', 'monthly', 'quarterly', 'yearly'] as const;
const directionLabels: Record<string, string> = { next: 'Next', prev: 'Previous' };
for (const period of periodLabels) {
for (const dir of directions) {
const id = `waypoint-go-to-${dir}-${period}`;
const name = `${directionLabels[dir]} ${period} note`;
this.addCommand({
id,
name,
callback: async () => {
await this.navigatePeriodNote(dir);
},
});
}
}
// ── Events ──
this.registerEvent(
@@ -319,6 +376,69 @@ export default class WaypointPlugin extends Plugin {
}
}
// ── Period note navigation (next/prev from current file) ──
/**
* Detect the period type from a filename's basename.
* Returns the period key and the parsed moment, or null if not a period note.
*/
private detectPeriodType(basename: string): { period: 'day' | 'week' | 'month' | 'quarter' | 'year'; date: moment.Moment } | null {
// YYYY-MM-DD → daily
if (/^\d{4}-\d{2}-\d{2}$/.test(basename)) {
return { period: 'day', date: moment(basename, 'YYYY-MM-DD') };
}
// GGGG-WWW → weekly (e.g. 2026-W24)
if (/^\d{4}-W\d{2}$/.test(basename)) {
return { period: 'week', date: moment(basename, 'GGGG-[W]WW') };
}
// YYYY-MM → monthly
if (/^\d{4}-\d{2}$/.test(basename)) {
return { period: 'month', date: moment(basename, 'YYYY-MM') };
}
// YYYY-Q# → quarterly
if (/^\d{4}-Q[1-4]$/.test(basename)) {
return { period: 'quarter', date: moment(basename, 'YYYY-[Q]Q') };
}
// YYYY → yearly
if (/^\d{4}$/.test(basename)) {
return { period: 'year', date: moment(basename, 'YYYY') };
}
return null;
}
/**
* Navigate to the next or previous period note based on the currently active file.
*/
async navigatePeriodNote(direction: 'next' | 'prev'): Promise<void> {
const file = this.app.workspace.getActiveFile();
if (!file) {
new Notice('No active file');
return;
}
const detected = this.detectPeriodType(file.basename);
if (!detected) {
new Notice('Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)');
return;
}
const { period, date } = detected;
if (!date.isValid()) {
new Notice(`Could not parse date from filename: ${file.basename}`);
return;
}
const amount = direction === 'next' ? 1 : -1;
// Map period to moment duration unit
const newDate = period === 'quarter'
? date.clone().add(amount * 3, 'months')
: date.clone().add(amount, `${period}s` as moment.unitOfTime.DurationConstructor);
await this.openPeriodNote(period, newDate);
}
// ── Redraw ──
private redrawAll(): void {