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:
1 parent
fbdc42b4a3
commit
a4714f6fa8
4 files changed
+133
-13
No files matched your search
@@ -2,15 +2,15 @@
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
*/
|
||||
|
||||
var V=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var U=(f,d)=>{for(var t in d)V(f,t,{get:d[t],enumerable:!0})},K=(f,d,t,e)=>{if(d&&typeof d=="object"||typeof d=="function")for(let a of H(d))!_.call(f,a)&&a!==t&&V(f,a,{get:()=>d[a],enumerable:!(e=Q(d,a))||e.enumerable});return f};var X=f=>K(V({},"__esModule",{value:!0}),f);var ee={};U(ee,{default:()=>R});module.exports=X(ee);var b=require("obsidian");var j={calendar:{firstDayOfWeek:1,showNoteIndicators:!0},daily:{folder:"periodic/daily",templateFile:"Templates/Daily note",nameFormat:"YYYY-MM-DD",typeProperty:"daily-note"},weekly:{folder:"periodic/weekly",templateFile:"Templates/Weekly note",nameFormat:"GGGG-[W]WW",typeProperty:"weekly-note"},monthly:{folder:"periodic/monthly",templateFile:"Templates/Monthly note",nameFormat:"YYYY-MM",typeProperty:"monthly-note"},quarterly:{folder:"periodic/quarterly",templateFile:"Templates/Quarterly note",nameFormat:"YYYY-[Q]Q",typeProperty:"quarterly-note"},yearly:{folder:"periodic/yearly",templateFile:"Templates/Yearly note",nameFormat:"YYYY",typeProperty:"yearly-note"},recentFiles:{maxItems:50,updateOn:"file-open",omittedPaths:[],omittedTags:[]}};var u=require("obsidian"),W=class extends u.PluginSettingTab{constructor(d,t,e,a){super(d,t),this.plugin=t,this.settings=e,this.onSettingsChange=a}display(){let{containerEl:d}=this;d.empty(),new u.Setting(d).setHeading().setName("Calendar"),new u.Setting(d).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(a=>{a.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(s=>{this.settings.calendar.firstDayOfWeek=parseInt(s,10),this.saveAndRefresh()})}),new u.Setting(d).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(a=>{a.setValue(this.settings.calendar.showNoteIndicators).onChange(s=>{this.settings.calendar.showNoteIndicators=s,this.saveAndRefresh()})}),new u.Setting(d).setHeading().setName("Periodic Note Paths"),this.addPeriodNoteSettings("Daily",this.settings.daily),this.addPeriodNoteSettings("Weekly",this.settings.weekly),this.addPeriodNoteSettings("Monthly",this.settings.monthly),this.addPeriodNoteSettings("Quarterly",this.settings.quarterly),this.addPeriodNoteSettings("Yearly",this.settings.yearly),new u.Setting(d).setHeading().setName("Recent Files"),new u.Setting(d).setName("Max items").setDesc("Maximum number of recent files to track.").addText(a=>{a.inputEl.setAttr("type","number"),a.inputEl.setAttr("placeholder","50"),a.setValue(String(this.settings.recentFiles.maxItems)),a.inputEl.onblur=()=>{let s=parseInt(a.getValue(),10);!isNaN(s)&&s>0&&(this.settings.recentFiles.maxItems=s,this.saveAndRefresh())}}),new u.Setting(d).setName("Update on").setDesc("When to add a file to the recent list.").addDropdown(a=>{a.addOption("file-open","File opened").addOption("file-edit","File changed").setValue(this.settings.recentFiles.updateOn).onChange(s=>{this.settings.recentFiles.updateOn=s,this.saveAndRefresh()})});let t=new DocumentFragment;t.appendText("Regex patterns for paths to exclude. One per line."),new u.Setting(d).setName("Omitted paths").setDesc(t).addTextArea(a=>{a.inputEl.setAttr("rows",4),a.setPlaceholder(`^archives/
|
||||
\\.png$`),a.setValue(this.settings.recentFiles.omittedPaths.join(`
|
||||
`)),a.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=a.getValue().split(`
|
||||
`).filter(s=>s.trim()),this.saveAndRefresh()}});let e=new DocumentFragment;e.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new u.Setting(d).setName("Omitted tags").setDesc(e).addTextArea(a=>{a.inputEl.setAttr("rows",4),a.setPlaceholder(`ignore
|
||||
archive`),a.setValue(this.settings.recentFiles.omittedTags.join(`
|
||||
`)),a.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=a.getValue().split(`
|
||||
`).filter(s=>s.trim()),this.saveAndRefresh()}})}addPeriodNoteSettings(d,t){new u.Setting(this.containerEl).setHeading().setName(d),new u.Setting(this.containerEl).setName("Folder").setDesc(`Folder path for ${d.toLowerCase()} notes.`).addText(e=>{e.setPlaceholder("periodic/daily"),e.setValue(t.folder),e.onChange(a=>{t.folder=a,this.saveAndRefresh()})}),new u.Setting(this.containerEl).setName("Name format").setDesc(`Date format for ${d.toLowerCase()} note filenames (moment.js format).`).addText(e=>{e.setPlaceholder("yyyy-MM-dd"),e.setValue(t.nameFormat),e.onChange(a=>{t.nameFormat=a,this.saveAndRefresh()})}),new u.Setting(this.containerEl).setName("Template file").setDesc("Path to the template file (without .md extension).").addText(e=>{e.setPlaceholder("Templates/Daily note"),e.setValue(t.templateFile),e.onChange(a=>{t.templateFile=a,this.saveAndRefresh()})}),new u.Setting(this.containerEl).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(e=>{e.setPlaceholder("daily-note"),e.setValue(t.typeProperty),e.onChange(a=>{t.typeProperty=a,this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveData(this.settings),this.onSettingsChange()}};var h=require("obsidian");var F=require("obsidian");function z(f,d,t){let e=(0,F.moment)({year:f,month:d,day:1}),a=(0,F.moment)(e).endOf("month"),s=(0,F.moment)(e).subtract((e.day()-t+7)%7,"days"),o=(0,F.moment)().startOf("day"),l=[],n=(0,F.moment)(s);for(;n.isBefore(a)||n.month()===d;){let i=[];for(let r=0;r<7;r++)i.push({date:(0,F.moment)(n),dayOfMonth:n.date(),isToday:n.isSame(o,"day"),isCurrentMonth:n.month()===d,isoWeekNumber:n.isoWeek()}),n.add(1,"day");if(l.push({weekNumber:i[0].isoWeekNumber,days:i}),l.length>=6)break}return l}var w="waypoint-view",A=class extends h.ItemView{constructor(t,e){super(t);this.redraw=()=>{this.contentEl.empty(),this.contentEl.addClass("waypoint-view"),this.renderFavorites(),this.renderRecentFiles(),this.renderCalendar()};this.currentDisplayMonth=(0,h.moment)().month();this.currentDisplayYear=(0,h.moment)().year();this.dragId=null;this.plugin=e}getViewType(){return w}getDisplayText(){return"Waypoint"}getIcon(){return"compass"}async onOpen(){this.redraw()}async onClose(){}renderCalendar(){let t=this.contentEl.createDiv({cls:"waypoint-section"});t.createDiv({cls:"waypoint-section-header",text:"Calendar"});let e=t.createDiv({cls:"waypoint-calendar"}),a=(0,h.moment)(),s=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),o=e.createDiv({cls:"waypoint-calendar-top"}),l=o.createDiv({cls:"waypoint-calendar-breadcrumb"}),n=s.format("[Q]Q");l.createSpan({cls:"waypoint-clickable",text:n}).addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",s)});let r=s.format("MMMM");l.createSpan({cls:"waypoint-clickable",text:r}).addEventListener("click",()=>{this.plugin.openPeriodNote("month",s)});let c=s.format("YYYY");l.createSpan({cls:"waypoint-clickable",text:c}).addEventListener("click",()=>{this.plugin.openPeriodNote("year",s)});let D=o.createDiv({cls:"waypoint-calendar-today-group"}),x=D.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(x,"chevron-left"),x.addEventListener("click",()=>this.navigateMonth(-1)),D.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,h.moment)().month(),this.currentDisplayYear=(0,h.moment)().year(),this.redraw()});let M=D.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(M,"chevron-right"),M.addEventListener("click",()=>this.navigateMonth(1));let E=e.createEl("table"),I=E.createEl("thead").createEl("tr");I.createEl("th",{text:""});let g=["sun","mon","tue","wed","thu","fri","sat"],Y=this.plugin.settings.calendar.firstDayOfWeek;for(let y=0;y<7;y++){let S=(Y+y)%7;I.createEl("th",{text:g[S]})}let v=E.createEl("tbody"),T=z(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let y of T){let S=v.createEl("tr"),N=S.createEl("td",{cls:"waypoint-weeknum"});N.setText(String(y.weekNumber)),N.addEventListener("click",()=>{let k=y.days[0].date;this.plugin.openPeriodNote("week",k)});for(let k of y.days){let C=S.createEl("td",{cls:"waypoint-day"});if(C.setText(String(k.dayOfMonth)),k.isCurrentMonth||C.addClass("other-month"),k.isToday&&C.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let O=k.date.format("YYYY-MM-DD");this.plugin.app.vault.getFiles().some(q=>q.extension==="md"&&q.basename===O)&&C.addClass("has-note")}C.addEventListener("click",()=>{this.plugin.openPeriodNote("day",k.date)})}}}navigateMonth(t){let e=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(t,"month");this.currentDisplayMonth=e.month(),this.currentDisplayYear=e.year(),this.redraw()}renderRecentFiles(){let t=this.contentEl.createDiv({cls:"waypoint-section waypoint-recent-files"});if(t.createDiv({cls:"waypoint-section-header",text:"Recent Files"}),this.plugin.recentFiles.length===0){
Line truncated
|
||||
type: ${o.typeProperty}
|
||||
var $=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var U=(f,d)=>{for(var t in d)$(f,t,{get:d[t],enumerable:!0})},K=(f,d,t,e)=>{if(d&&typeof d=="object"||typeof d=="function")for(let n of H(d))!_.call(f,n)&&n!==t&&$(f,n,{get:()=>d[n],enumerable:!(e=z(d,n))||e.enumerable});return f};var X=f=>K($({},"__esModule",{value:!0}),f);var ee={};U(ee,{default:()=>R});module.exports=X(ee);var u=require("obsidian");var j={calendar:{firstDayOfWeek:1,showNoteIndicators:!0},daily:{folder:"periodic/daily",templateFile:"Templates/Daily note",nameFormat:"YYYY-MM-DD",typeProperty:"daily-note"},weekly:{folder:"periodic/weekly",templateFile:"Templates/Weekly note",nameFormat:"GGGG-[W]WW",typeProperty:"weekly-note"},monthly:{folder:"periodic/monthly",templateFile:"Templates/Monthly note",nameFormat:"YYYY-MM",typeProperty:"monthly-note"},quarterly:{folder:"periodic/quarterly",templateFile:"Templates/Quarterly note",nameFormat:"YYYY-[Q]Q",typeProperty:"quarterly-note"},yearly:{folder:"periodic/yearly",templateFile:"Templates/Yearly note",nameFormat:"YYYY",typeProperty:"yearly-note"},recentFiles:{maxItems:50,updateOn:"file-open",omittedPaths:[],omittedTags:[]}};var g=require("obsidian"),W=class extends g.PluginSettingTab{constructor(d,t,e,n){super(d,t),this.plugin=t,this.settings=e,this.onSettingsChange=n}display(){let{containerEl:d}=this;d.empty(),new g.Setting(d).setHeading().setName("Calendar"),new g.Setting(d).setName("First day of week").setDesc("Which day the calendar week starts on.").addDropdown(n=>{n.addOption("0","Sunday").addOption("1","Monday").setValue(String(this.settings.calendar.firstDayOfWeek)).onChange(r=>{this.settings.calendar.firstDayOfWeek=parseInt(r,10),this.saveAndRefresh()})}),new g.Setting(d).setName("Show note indicators").setDesc("Show a dot on days that have existing notes.").addToggle(n=>{n.setValue(this.settings.calendar.showNoteIndicators).onChange(r=>{this.settings.calendar.showNoteIndicators=r,this.saveAndRefresh()})}),new g.Setting(d).setHeading().setName("Periodic Note Paths"),this.addPeriodNoteSettings("Daily",this.settings.daily),this.addPeriodNoteSettings("Weekly",this.settings.weekly),this.addPeriodNoteSettings("Monthly",this.settings.monthly),this.addPeriodNoteSettings("Quarterly",this.settings.quarterly),this.addPeriodNoteSettings("Yearly",this.settings.yearly),new g.Setting(d).setHeading().setName("Recent Files"),new g.Setting(d).setName("Max items").setDesc("Maximum number of recent files to track.").addText(n=>{n.inputEl.setAttr("type","number"),n.inputEl.setAttr("placeholder","50"),n.setValue(String(this.settings.recentFiles.maxItems)),n.inputEl.onblur=()=>{let r=parseInt(n.getValue(),10);!isNaN(r)&&r>0&&(this.settings.recentFiles.maxItems=r,this.saveAndRefresh())}}),new g.Setting(d).setName("Update on").setDesc("When to add a file to the recent list.").addDropdown(n=>{n.addOption("file-open","File opened").addOption("file-edit","File changed").setValue(this.settings.recentFiles.updateOn).onChange(r=>{this.settings.recentFiles.updateOn=r,this.saveAndRefresh()})});let t=new DocumentFragment;t.appendText("Regex patterns for paths to exclude. One per line."),new g.Setting(d).setName("Omitted paths").setDesc(t).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`^archives/
|
||||
\\.png$`),n.setValue(this.settings.recentFiles.omittedPaths.join(`
|
||||
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedPaths=n.getValue().split(`
|
||||
`).filter(r=>r.trim()),this.saveAndRefresh()}});let e=new DocumentFragment;e.appendText("Regex patterns for frontmatter tags to exclude. One per line."),new g.Setting(d).setName("Omitted tags").setDesc(e).addTextArea(n=>{n.inputEl.setAttr("rows",4),n.setPlaceholder(`ignore
|
||||
archive`),n.setValue(this.settings.recentFiles.omittedTags.join(`
|
||||
`)),n.inputEl.onblur=()=>{this.settings.recentFiles.omittedTags=n.getValue().split(`
|
||||
`).filter(r=>r.trim()),this.saveAndRefresh()}})}addPeriodNoteSettings(d,t){new g.Setting(this.containerEl).setHeading().setName(d),new g.Setting(this.containerEl).setName("Folder").setDesc(`Folder path for ${d.toLowerCase()} notes.`).addText(e=>{e.setPlaceholder("periodic/daily"),e.setValue(t.folder),e.onChange(n=>{t.folder=n,this.saveAndRefresh()})}),new g.Setting(this.containerEl).setName("Name format").setDesc(`Date format for ${d.toLowerCase()} note filenames (moment.js format).`).addText(e=>{e.setPlaceholder("yyyy-MM-dd"),e.setValue(t.nameFormat),e.onChange(n=>{t.nameFormat=n,this.saveAndRefresh()})}),new g.Setting(this.containerEl).setName("Template file").setDesc("Path to the template file (without .md extension).").addText(e=>{e.setPlaceholder("Templates/Daily note"),e.setValue(t.templateFile),e.onChange(n=>{t.templateFile=n,this.saveAndRefresh()})}),new g.Setting(this.containerEl).setName("Type property").setDesc("Value for the 'type' frontmatter property.").addText(e=>{e.setPlaceholder("daily-note"),e.setValue(t.typeProperty),e.onChange(n=>{t.typeProperty=n,this.saveAndRefresh()})})}async saveAndRefresh(){await this.plugin.saveData(this.settings),this.onSettingsChange()}};var h=require("obsidian");var T=require("obsidian");function Q(f,d,t){let e=(0,T.moment)({year:f,month:d,day:1}),n=(0,T.moment)(e).endOf("month"),r=(0,T.moment)(e).subtract((e.day()-t+7)%7,"days"),a=(0,T.moment)().startOf("day"),s=[],o=(0,T.moment)(r);for(;o.isBefore(n)||o.month()===d;){let i=[];for(let l=0;l<7;l++)i.push({date:(0,T.moment)(o),dayOfMonth:o.date(),isToday:o.isSame(a,"day"),isCurrentMonth:o.month()===d,isoWeekNumber:o.isoWeek()}),o.add(1,"day");if(s.push({weekNumber:i[0].isoWeekNumber,days:i}),s.length>=6)break}return s}var b="waypoint-view",Y=class extends h.ItemView{constructor(t,e){super(t);this.redraw=()=>{this.contentEl.empty(),this.contentEl.addClass("waypoint-view"),this.renderFavorites(),this.renderRecentFiles(),this.renderCalendar()};this.currentDisplayMonth=(0,h.moment)().month();this.currentDisplayYear=(0,h.moment)().year();this.dragId=null;this.plugin=e}getViewType(){return b}getDisplayText(){return"Waypoint"}getIcon(){return"compass"}async onOpen(){this.redraw()}async onClose(){}renderCalendar(){let t=this.contentEl.createDiv({cls:"waypoint-section"});t.createDiv({cls:"waypoint-section-header",text:"Calendar"});let e=t.createDiv({cls:"waypoint-calendar"}),n=(0,h.moment)(),r=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth,day:1}),a=e.createDiv({cls:"waypoint-calendar-top"}),s=a.createDiv({cls:"waypoint-calendar-breadcrumb"}),o=r.format("[Q]Q");s.createSpan({cls:"waypoint-clickable",text:o}).addEventListener("click",()=>{this.plugin.openPeriodNote("quarter",r)});let l=r.format("MMMM");s.createSpan({cls:"waypoint-clickable",text:l}).addEventListener("click",()=>{this.plugin.openPeriodNote("month",r)});let c=r.format("YYYY");s.createSpan({cls:"waypoint-clickable",text:c}).addEventListener("click",()=>{this.plugin.openPeriodNote("year",r)});let D=a.createDiv({cls:"waypoint-calendar-today-group"}),I=D.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(I,"chevron-left"),I.addEventListener("click",()=>this.navigateMonth(-1)),D.createEl("button",{cls:"waypoint-calendar-today-btn",text:"Today"}).addEventListener("click",()=>{this.currentDisplayMonth=(0,h.moment)().month(),this.currentDisplayYear=(0,h.moment)().year(),this.redraw()});let M=D.createEl("button",{cls:"waypoint-calendar-nav-btn"});(0,h.setIcon)(M,"chevron-right"),M.addEventListener("click",()=>this.navigateMonth(1));let E=e.createEl("table"),x=E.createEl("thead").createEl("tr");x.createEl("th",{text:""});let y=["sun","mon","tue","wed","thu","fri","sat"],N=this.plugin.settings.calendar.firstDayOfWeek;for(let v=0;v<7;v++){let S=(N+v)%7;x.createEl("th",{text:y[S]})}let w=E.createEl("tbody"),C=Q(this.currentDisplayYear,this.currentDisplayMonth,this.plugin.settings.calendar.firstDayOfWeek);for(let v of C){let S=w.createEl("tr"),B=S.createEl("td",{cls:"waypoint-weeknum"});B.setText(String(v.weekNumber)),B.addEventListener("click",()=>{let k=v.days[0].date;this.plugin.openPeriodNote("week",k)});for(let k of v.days){let P=S.createEl("td",{cls:"waypoint-day"});if(P.setText(String(k.dayOfMonth)),k.isCurrentMonth||P.addClass("other-month"),k.isToday&&P.addClass("today"),this.plugin.settings.calendar.showNoteIndicators){let O=k.date.format("YYYY-MM-DD");this.plugin.app.vault.getFiles().some(V=>V.extension==="md"&&V.basename===O)&&P.addClass("has-note")}P.addEventListener("click",()=>{this.plugin.openPeriodNote("day",k.date)})}}}navigateMonth(t){let e=(0,h.moment)({year:this.currentDisplayYear,month:this.currentDisplayMonth}).add(t,"month");this.currentDisplayMonth=e.month(),this.currentDisplayYear=e.year(),this.redraw()}renderRecentFiles(){let t=this.contentEl.createDiv({cls:"waypoint-section waypoint-recent-files"});if(t.createDiv({cls:"waypoint-section-header",text:"Recent Files"}),this.plugin.recentFiles.length===0){
Line truncated
|
||||
type: ${a.typeProperty}
|
||||
date: ${e.format("YYYY-MM-DD")}
|
||||
---
|
||||
|
||||
`;i=await this.app.vault.create(n,c)}}catch(r){new b.Notice(`Failed to create ${s.label.toLowerCase()} note: ${r.message}`);return}new b.Notice(`Created ${s.label.toLowerCase()} note: ${l}`)}i&&await this.app.workspace.getLeaf(!1).openFile(i)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let t=this.app.workspace.getLeavesOfType(w);for(let e of t)e.view instanceof A&&e.view.redraw()}async getNotesForDate(t){return this.app.vault.getFiles().filter(e=>e.extension==="md"&&e.basename===t)}async hasNoteForDate(t){return this.app.vault.getFiles().some(e=>e.extension==="md"&&e.basename===t)}};
|
||||
`;i=await this.app.vault.create(o,c)}}catch(l){new u.Notice(`Failed to create ${r.label.toLowerCase()} note: ${l.message}`);return}new u.Notice(`Created ${r.label.toLowerCase()} note: ${s}`)}i&&await this.app.workspace.getLeaf(!1).openFile(i)}detectPeriodType(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)?{period:"day",date:(0,u.moment)(t,"YYYY-MM-DD")}:/^\d{4}-W\d{2}$/.test(t)?{period:"week",date:(0,u.moment)(t,"GGGG-[W]WW")}:/^\d{4}-\d{2}$/.test(t)?{period:"month",date:(0,u.moment)(t,"YYYY-MM")}:/^\d{4}-Q[1-4]$/.test(t)?{period:"quarter",date:(0,u.moment)(t,"YYYY-[Q]Q")}:/^\d{4}$/.test(t)?{period:"year",date:(0,u.moment)(t,"YYYY")}:null}async navigatePeriodNote(t){let e=this.app.workspace.getActiveFile();if(!e){new u.Notice("No active file");return}let n=this.detectPeriodType(e.basename);if(!n){new u.Notice("Current file is not a periodic note (daily/weekly/monthly/quarterly/yearly)");return}let{period:r,date:a}=n;if(!a.isValid()){new u.Notice(`Could not parse date from filename: ${e.basename}`);return}let s=t==="next"?1:-1,o=r==="quarter"?a.clone().add(s*3,"months"):a.clone().add(s,`${r}s`);await this.openPeriodNote(r,o)}redrawAll(){this.broadcastRedraw()}broadcastRedraw(){let t=this.app.workspace.getLeavesOfType(b);for(let e of t)e.view instanceof Y&&e.view.redraw()}async getNotesForDate(t){return this.app.vault.getFiles().filter(e=>e.extension==="md"&&e.basename===t)}async hasNoteForDate(t){return this.app.vault.getFiles().some(e=>e.extension==="md"&&e.basename===t)}};
|
||||
+1
-1
@@ -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
@@ -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
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user