<%* /*

๐ŸŒฟ 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 &ge; [
    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 &le; end;

const scheduledThisWeek = getWorkDays(p)
  .some(d &ge; d >= start && d &le; 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);

%>

Built with LogoFlowershow