obsidian-periodic-notes
obsidian-periodic-notes copied to clipboard
Create weekly notes with the dates for the start and end in the title
So I know this isn't part of the usual formatting syntax, but would it be at all possible to include the start and end days of a week in the note title? It's hard for me to parse exactly which weeks correspond to which days, so having the days really helps.
I'm currently doing a hacky method using the default daily note plugin and templater where it calculates the current weekly note and navigates there, but I would like something more properly integrated.
Examples of notes in my vault:
- 2022-W53 (Dec 25 - Dec 31)
- 2023-W04 (Jan 22 - Jan 28)
For reference, this is the current hacky approach I'm using
Templater code at the top of my weekly notes
<%*
let title = tp.file.title
if (title.startsWith("Untitled")) {
// Title format: "YYYY-[W]ww + (MMM {sun_date} - MMM {sat_date})"
week = tp.date.now("GGGG-[W]ww")
wk_start = tp.date.weekday("MMM DD", 0)
wk_end = tp.date.weekday("MMM DD", 6)
title = `${week} (${wk_start} - ${wk_end})`
console.log(title);
await tp.file.rename(`${title}`);
}
// Set up the previous and next week variables
pweek = tp.date.now("GGGG-[W]ww", -7)
pwk_start = tp.date.weekday("MMM DD", -7)
pwk_end = tp.date.weekday("MMM DD", -1)
pwk_title = `${pweek} (${pwk_start} - ${pwk_end})`
nweek = tp.date.now("GGGG-[W]ww", +7)
nwk_start = tp.date.weekday("MMM DD", +7)
nwk_end = tp.date.weekday("MMM DD", +13)
nwk_title = `${nweek} (${nwk_start} - ${nwk_end})`
// This will output the renamed title with heading level 1
// and also use up the blank line this execution template occupies
tR += "# " + `${title}`
-%>
Templater code at the top of my weekly note opening file
<%*
async function test() {
// Title format: "YYYY-[W]ww + (MMM {sun_date} - MMM {sat_date})"
week = tp.date.now("GGGG-[W]ww")
wk_start = tp.date.weekday("MMM DD", 0)
wk_end = tp.date.weekday("MMM DD", 6)
title = `${week} (${wk_start} - ${wk_end})`
//console.log(title)
var fldr = "1. Journal/Weekly Notes/";
var year = tp.date.now("GGGG");
var path = fldr + year + "/" + title + ".md"
//console.log(path)
var exists = await tp.file.exists(path)
//console.log(exists)
if (!exists) {
console.log("file doesn't exists")
// console.log("Creating file "+title+"'at " +fldr+year+'/');
// This does throw an error since the folder will (usually) be created,
// but it shouldn't matter. Can't get try
try {
this.app.vault.createFolder(fldr+year);
} catch(err) { console.log(err)}
this.app.vault.create(fldr+year+'/Untitled.md', "");
await new Promise(resolve => setTimeout(resolve, 1000));
}
let weeklyNote = tp.file.find_tfile(title);
//let temp_nav = tp.file.find_tfile("zz_meta/nav_temp/99989");
var opt = app['internalPlugins']['plugins']['daily-notes']['instance']['options']['folder']
var format = app['internalPlugins']['plugins']['daily-notes']['instance']['options']['format']
var temp_nav_2 = tp.file.find_tfile( opt + '/' + format );
// console.log(temp_nav_2);
app.workspace.activeLeaf.openFile( weeklyNote );
await new Promise(resolve => setTimeout(resolve, 2000));
this.app.vault.delete( temp_nav_2 );
}
test();
%>
It would be very useful if template tags worked for the filename format field.
For example supporting syntax like {{friday:DD}}
seems to be the missing piece that would allow me to achieve what I want, which is something like this:
2023 → Week 24, June 18-23
(Since this is in a vault used only for work, I want dates from Monday to Friday.)
This is valuable because I am aware of dates but I have no idea what week number corresponds to which dates off the top of my head. I want the week number to make things sort correctly, but I want the dates to make the title actually meaningful to me.