Hello, I want to create a list of weekly note links for a specific quarter. (Use case: When I manually create a quarter note through the periodic notes plugin I want the list of relevant weekly notes there.)
And sometimes year does have 53 weeks, so I want to take this into account in the code.
And it would be awesome if it used the template I specified for the newly created weekly notes.
Things I have tried
I have created this code but it is not working yet. But you get the idea. I appreciate any suggestions and help.
<%*
const currentYear = tp.date.now(“YYYY”); // Current year
const currentQuarter = Math.ceil((tp.date.now(“M”) - 1) / 3) + 1; // Calculate the current quarter
// Determine if the year has 52 or 53 weeks
const maxWeeksInYear = tp.date.now(“w”, `${currentYear}-12-31`) === “53” ? 53 : 52;
// Set start and end weeks for the current quarter
const startWeek = (currentQuarter - 1) * 13 + 1;
const endWeek = Math.min(currentQuarter * 13, maxWeeksInYear);
let weeklyNotes = ;
// Loop over each week in the quarter range
for (let week = startWeek; week <= endWeek; week++) {
const weekNoteName = `${currentYear}-W${week.toString().padStart(2, '0')}`;
const weekFilePath = `06 - Daily Journal/${currentYear}/${weekNoteName}`; // Define note path
// Check if the file exists, create if it doesn’t
if (!(await tp.file.exists(weekFilePath))) {
await tp.file.create_new(“”, weekNoteName, false, `06 - Daily Journal/${currentYear}`);
}
// Add the note link to the list with a readable label
weeklyNotes.push(`[[${weekNoteName}|Week ${week} ${currentYear}]]`);
}
// Output the weekly notes list for the current quarter
tR += “List of weekly notes:\n” + weeklyNotes.join(“\n”);
%>