<%* const title = await tp.system.prompt("What is the list for?"); const taskCount = Number(await tp.system.prompt("How many tasks total?")); const completedCount = Number(await tp.system.prompt("How many already completed?")); const dueDateStr = await tp.system.prompt("Due date (YYYY-MM-DD)"); const tag = title.toLowerCase().replace(/\s+/g, "-"); function formatDate(date) { return date.getFullYear() + "-" + String(date.getMonth() + 1).padStart(2, "0") + "-" + String(date.getDate()).padStart(2, "0"); } tR += `# ${title}\n\n`; // Dynamic dashboard tR += "```dataviewjs\n"; tR += "const tasks = dv.current().file.tasks;\n"; tR += `const filtered = tasks.where(t => t.text.includes("#${tag}"));\n\n`; tR += "const total = filtered.length;\n"; tR += "const completed = filtered.where(t => t.completed).length;\n"; tR += "const remaining = total - completed;\n\n"; tR += `const due = new Date("${dueDateStr}");\n`; tR += "const today = new Date();\n"; tR += "today.setHours(0,0,0,0);\n"; tR += "due.setHours(0,0,0,0);\n"; tR += "const days = Math.max(1, Math.ceil((due - today) / (1000 * 60 * 60 * 24)) + 1);\n\n"; tR += "dv.paragraph(`Tasks: ${total}`);\n"; tR += "dv.paragraph(`Completed: ${completed}`);\n"; tR += "dv.paragraph(`Remaining: ${remaining}`);\n"; tR += "dv.paragraph(`Days left: ${days}`);\n"; tR += "dv.paragraph(`Tasks per day: ${Math.ceil(remaining / days)}`);\n"; tR += "```\n\n"; const today = new Date(); today.setHours(0, 0, 0, 0); const dueDate = new Date(dueDateStr); dueDate.setHours(0, 0, 0, 0); const daysLeft = Math.max( 1, Math.ceil((dueDate - today) / (1000 * 60 * 60 * 24)) + 1 ); const remainingTasks = taskCount - completedCount; const base = Math.floor(remainingTasks / daysLeft); const remainder = remainingTasks % daysLeft; // Completed tasks first for (let i = 1; i <= completedCount; i++) { tR += `- [x] ${title} ${i} #${tag}\n`; } // Remaining tasks distributed across days let task = completedCount + 1; for (let day = 0; day < daysLeft; day++) { const tasksToday = base + (day < remainder ? 1 : 0); const date = new Date(today); date.setDate(today.getDate() + day); const dateStr = formatDate(date); for (let i = 0; i < tasksToday; i++) { tR += `- [ ] ${title} ${task} 📅 ${dateStr} #${tag}\n`; task++; } } %>