Weekly Plan Template
<%* /*
๐ฟ STUDY NOOK: WEEKLY PLAN TEMPLATE
*/
// 1. Default to Monday of the current week const defaultMonday = window.moment() .startOf("isoWeek") .format("MM/DD/YY");
// 2. Ask which week to plan const dateInput = await tp.system.prompt( "Choose a date in the week (MM/DD/YY)", defaultMonday );
if (!dateInput) return;
// 3. Validate the date const selectedDate = window.moment( dateInput, "MM/DD/YY", true );
if (!selectedDate.isValid()) { new Notice("Please use MM/DD/YY."); return; }
// 4. Determine Monday and Sunday const monday = selectedDate.clone() .startOf("isoWeek");
const sunday = monday.clone() .add(6, "days");
const weekStart = monday.format("YYYY-MM-DD");
const displayStart = monday.format("MMMM D"); const displayEnd = sunday.format("MMMM D, YYYY");
// 5. Create the pretty filename const title = "Week of " + monday.format("MMMM D, YYYY");
// 6. Set the Weekly Plans folder const folder = "study nook/School/Weekly Plans"; const destination = folder + "/" + title + ".md";
// Create folder if necessary if (!app.vault.getAbstractFileByPath(folder)) { await app.vault.createFolder(folder); }
// Prevent duplicate weekly plans if (app.vault.getAbstractFileByPath(destination)) { new Notice("A plan for this week already exists."); return; }
// 7. Build the automatic homework schedule const fence = String.fromCharCode(96).repeat(3);
const schedule = `
๐ธ My Weekly Homework Schedule
${fence}dataviewjs // ===================================== // ๐ฟ WEEKLY HOMEWORK PLANNER // =====================================
const current = dv.current();
// Use the week's Monday property const weekValue = current.week_start || current.week;
const weekDate = weekValue ? (typeof weekValue.toISODate === "function" ? weekValue.toISODate() : String(weekValue)) : moment().format("YYYY-MM-DD");
const monday = moment(weekDate).startOf("isoWeek"); const sunday = monday.clone().add(6, "days");
const assignments = dv.pages( '"study nook/School/Assignments"' ).where(p โฅ p.due);
// Convert work dates to YYYY-MM-DD internally function dateString(value) { if (!value) return "";
if (typeof value.toISODate === "function") { return value.toISODate(); }
const parsed = moment( String(value).trim(), ["MM/DD/YY", "MM/DD/YYYY", "YYYY-MM-DD"], true );
if (!parsed.isValid()) return "";
return parsed.format("YYYY-MM-DD"); }
// Read multiple scheduled work days function getWorkDays(page) { if (!page.work_days) return [];
const values = typeof page.work_days.array === "function" ? page.work_days.array() : Array.isArray(page.work_days) ? page.work_days : [page.work_days];
return values .map(dateString) .filter(d โฅ d !== ""); }
// Check completion function isComplete(page) { const status = String(page.status || "") .trim() .toLowerCase();
return ( status === "done" || status === "completed" || status === "complete" || page.completed === true ); }
// ===================================== // ๐ท DAILY HOMEWORK SCHEDULE // =====================================
for (let i = 0; i < 7; i++) {
const day = monday.clone().add(i, "days"); const key = day.format("YYYY-MM-DD");
dv.header( 3, "๐ฟ " + day.format("dddd, MMMM D") );
const tasks = assignments .where(p โฅ getWorkDays(p).includes(key)) .sort(p โฅ p.due, "asc");
if (tasks.length > 0) {
dv.table(
["Assignment", "Due", "Status"],
tasks.map(p ≥ [
p.file.link,
moment(dateString(p.due)).format("MMM D"),
p.status || "Not started"
])
);
} else {
if (i === 5) {
dv.paragraph(
"๐ธ Nothing scheduled! Enjoy your free Saturday."
);
} else if (i === 6) {
dv.paragraph(
"๐ฑ Nothing scheduled. Time for a weekly reset!"
);
} else {
dv.paragraph(
"๐ฑ Nothing scheduled yet. Enjoy some breathing room!"
);
}
} }
// ===================================== // ๐ UNSCHEDULED DEADLINES // =====================================
dv.header(3, "๐ Still needs scheduling");
const start = monday.format("YYYY-MM-DD"); const end = sunday.format("YYYY-MM-DD");
const unscheduled = assignments .where(p โฅ {
const due = dateString(p.due);
const dueThisWeek =
due >= start && due ≤ end;
const scheduledThisWeek = getWorkDays(p)
.some(d ≥ d >= start && d ≤ end);
return dueThisWeek &&
!scheduledThisWeek &&
!isComplete(p);
}) .sort(p โฅ p.due, "asc");
if (unscheduled.length > 0) {
dv.table( ["Assignment", "Due", "Priority"], unscheduled.map(p โฅ [ p.file.link, moment(dateString(p.due)) .format("ddd, MMM D"), p.priority || "Medium" ]) );
} else {
dv.paragraph( "๐ธ All assignments due this week have work days scheduled!" );
} ${fence} `;
// 8. Generate the COMPLETE weekly plan // Both week and week_start use the SAME Monday.
tR = [ "โ", "type: weekly-plan", "week: " + weekStart, "week_start: " + weekStart, "โ", "", "# ๐ฟ Week of " + displayStart + " โ " + displayEnd, "", "## ๐ชท Three priorities", "", "1. ", "2. ", "3. ", "", schedule, "", "## ๐ Daily plan", "", "### ๐ฟ Monday", "- [ ] ", "", "### ๐ฟ Tuesday", "- [ ] ", "", "### ๐ฟ Wednesday", "- [ ] ", "", "### ๐ฟ Thursday", "- [ ] ", "", "### ๐ฟ Friday", "- [ ] ", "", "### ๐ธ Saturday", "- [ ] ", "", "### ๐ฑ Sunday", "- [ ] Weekly reset", "", "## โฐ Deadlines to protect time for", "", "- ", "", "## ๐ผ Weekly review", "", "- Finished:", "- Carry over:", "- Next week's first step:" ].join("\n");
// 9. Move to the Weekly Plans folder await tp.file.move(folder + "/" + title);
%>