|
class Dated { |
|
constructor() { // Constructor |
|
this.tyiwStartWeek = 40; |
|
this.birthdayFile = app.vault.adapter.basePath + "/assets/birthdays.json"; |
|
|
|
this.parseDate = (filename) => { |
|
const titledate = filename.replace("_week", ''); |
|
const day = moment(titledate); |
|
const dayOfWeek = day.isoWeekday(); |
|
|
|
let theMonday = moment(day).day(1); |
|
let nextWorkDay = moment(day).add(1, 'd'); |
|
let nextWorkDayName = 'tomorrow'; |
|
if (dayOfWeek === 0 || dayOfWeek === 7) { |
|
theMonday = moment(day).add(-1, 'week').day(1); |
|
} else if (dayOfWeek > 4) { |
|
nextWorkDay = moment(theMonday).add(1, 'week'); |
|
nextWorkDayName = 'Monday'; |
|
} |
|
|
|
return { |
|
day: day, |
|
nextWorkDay: nextWorkDay, |
|
nextWorkDayName: nextWorkDayName, |
|
|
|
lastMonday: moment(theMonday).add(-1, 'week'), |
|
monday: theMonday, |
|
nextMonday: moment(theMonday).add(1, 'week') |
|
} |
|
} |
|
|
|
this.dailyFile = (start, target) => { |
|
return target.format("YYYY-MM-DD[.md]"); |
|
} |
|
|
|
this.dayOfWeekFile = (monday, dayOfWeek) => { |
|
return this.dailyFile(monday, moment(monday).day(dayOfWeek)); |
|
} |
|
|
|
this.weeklyFile = (start, monday) => { |
|
return monday.format("YYYY-MM-DD[_week.md]"); |
|
} |
|
|
|
this.monthlyFile = (start, target) => { |
|
return target.format("YYYY-MM[_month.md]"); |
|
} |
|
|
|
this.yearlyFile = (start, target) => { |
|
return target.format("YYYY[_year.md]"); |
|
} |
|
|
|
this.tyiwFile = (target) => { |
|
return target.format("[tyiw-journal]-YYYY-MM-DD[.md]"); |
|
} |
|
|
|
this.daily = (filename) => { |
|
const dates = this.parseDate(filename); |
|
const header = '# My Day\n' |
|
+ dates.day.format("dddd, MMMM DD, YYYY") |
|
+ ' .... [' + dates.nextWorkDayName + '](' + this.dailyFile(dates.day, dates.nextWorkDay) + ') \n' |
|
+ 'Week of [' + dates.monday.format("MMMM DD") + '](' + this.weeklyFile(dates.day, dates.monday) + ') \n'; |
|
|
|
return { |
|
dates: dates, |
|
header: header |
|
} |
|
} |
|
|
|
this.tyiwWeeklyJournal = (filename) => { |
|
const dates = this.parseDate(filename.replace('tyiw-journal-', '')); |
|
let week = dates.monday.week(); |
|
if (week >= this.tyiwStartWeek) { |
|
week = week - this.tyiwStartWeek + 1; |
|
} else { |
|
week = (52 - this.tyiwStartWeek) + week + 1; |
|
} |
|
return { |
|
tags: "'me/tyiw'", |
|
week: week, |
|
weekOf: dates.monday.format("MMMM DD, YYYY"), |
|
dates: dates, |
|
prefix: dates.monday.format("tyiw-journal-YYYY-MM-DD") |
|
} |
|
} |
|
|
|
this.weekly = (filename) => { |
|
const dates = this.parseDate(filename); |
|
const thisMonthFile = this.monthlyFile(dates.monday, dates.monday); |
|
const lastWeekFile = this.weeklyFile(dates.monday, dates.lastMonday); |
|
const lastMonthFile = this.monthlyFile(dates.monday, dates.lastMonday); |
|
let monthlyReflection = ''; |
|
let upcoming = `> }_year.md#${dates.monday.format("MMMM")})\n` |
|
+ `> }_year.md#^todoist)`; |
|
|
|
var header = `# Week of ${dates.monday.format("MMM D")}\n` |
|
+ `[< ${dates.lastMonday.format("MMM D")}](${lastWeekFile}) --` |
|
+ ` [Mo](${this.dayOfWeekFile(dates.monday, 1)})` |
|
+ ` [Tu](${this.dayOfWeekFile(dates.monday, 2)})` |
|
+ ` [We](${this.dayOfWeekFile(dates.monday, 3)})` |
|
+ ` [Th](${this.dayOfWeekFile(dates.monday, 4)})` |
|
+ ` [Fr](${this.dayOfWeekFile(dates.monday, 5)})` |
|
+ ` -- [${dates.nextMonday.format("MMM D")} >](${this.weeklyFile(dates.monday, dates.nextMonday)}) \n` |
|
+ `Goals for [${dates.monday.format("MMMM")}](${thisMonthFile})`; |
|
|
|
if (dates.monday.month() !== dates.nextMonday.month()) { |
|
header += `, [${dates.nextMonday.format("MMMM")}](${this.monthlyFile(dates.monday, dates.nextMonday)})`; |
|
upcoming += `\n> }_year.md#${dates.nextMonday.format("MMMM")})` |
|
monthlyReflection = |
|
`- [ ] [Reflect on last month](${lastMonthFile})\n` |
|
+ `- [ ] [Goals for this month](${this.monthlyFile(dates.monday, dates.nextMonday)})`; |
|
} else if (dates.monday.month() !== dates.lastMonday.month()) { |
|
monthlyReflection = |
|
`- [ ] [Reflect on last month](${lastMonthFile})\n` |
|
+ `- [ ] [Goals for this month](${thisMonthFile})`; |
|
} |
|
|
|
const log = |
|
`### Log ${this.dayOfWeekFile(dates.monday, 1)}\n` |
|
+ `}#Log)\n\n` |
|
+ `### Log ${this.dayOfWeekFile(dates.monday, 2)}\n` |
|
+ `}#Log)\n\n` |
|
+ `### Log ${this.dayOfWeekFile(dates.monday, 3)}\n` |
|
+ `}#Log)\n\n` |
|
+ `### Log ${this.dayOfWeekFile(dates.monday, 4)}\n` |
|
+ `}#Log)\n\n` |
|
+ `### Log ${this.dayOfWeekFile(dates.monday, 5)}\n` |
|
+ `}#Log)\n\n` |
|
+ `### Log ${this.dayOfWeekFile(dates.monday, 6)}\n` |
|
+ `}#Log)\n\n` |
|
+ `### Log ${this.dayOfWeekFile(dates.monday, 7)}\n` |
|
+ `}#Log)\n\n`; |
|
|
|
const dataview = |
|
`dataviewjs |
|
const { Project } = window.customJS; |
|
const tasks = Project.demesneQuestTasks(dv) |
|
.where(t => Project.completedThisWeek(dv.current(), t)); |
|
dv.list(Project.tasksToPageList(tasks, dv));` |
|
|
|
const activity = |
|
`> [!activity] |
|
> \`\`\`dataviewjs |
|
> const { Activity } = window.customJS; |
|
> const today = DateTime.fromISO("${dates.monday.format("YYYY-MM-DD")}"); |
|
> Activity.barChart(today, dv, this.container, DateTime); |
|
> \`\`\``; |
|
|
|
return { |
|
dates: dates, |
|
header: header, |
|
log: log, |
|
dataview: dataview, |
|
activity: activity, |
|
monthName: `${dates.monday.format("MMMM")}`, |
|
monthlyReflection: monthlyReflection, |
|
weeklyReflection: `${lastMonthFile}#${dates.lastMonday.format("YYYY-MM-DD")}`, |
|
upcoming: upcoming, |
|
lastWeekFile: lastWeekFile |
|
} |
|
} |
|
|
|
this.monthlyDates = (fileName) => { |
|
const dateString = fileName.replace('.md', '').replace('_month', '-01'); |
|
const date = moment(dateString); |
|
const lastMonth = moment(date).add(-1, 'month'); |
|
const nextMonth = moment(date).add(1, 'month'); |
|
|
|
let firstMonday = moment(date).startOf('month').day("Monday"); |
|
if (firstMonday.date() > 7) { |
|
// We might be at the end of the previous month. So |
|
// find the next Monday.. the first Monday *in* the month |
|
firstMonday.add(7, 'd'); |
|
} |
|
|
|
return { |
|
monthYear: date.format("MMMM YYYY"), |
|
month: date.format("MMMM"), |
|
year: date.format("YYYY"), |
|
lastMonth: lastMonth.format("MMMM"), |
|
lastMonthFile: this.monthlyFile(date, lastMonth), |
|
nextMonth: nextMonth.format("MMMM"), |
|
nextMonthFile: this.monthlyFile(date, nextMonth), |
|
firstMonday: firstMonday |
|
} |
|
} |
|
|
|
this.monthly = (filename) => { |
|
const dates = this.monthlyDates(filename); |
|
const header = `# Goals for ${dates.monthYear}\n` |
|
+ `[< ${dates.lastMonth}](${dates.lastMonthFile}) -- [${dates.nextMonth} >](${dates.nextMonthFile})`; |
|
|
|
return { |
|
dates: dates, |
|
yearEmbed: `}#${dates.month})`, |
|
header: header |
|
} |
|
} |
|
|
|
this.yearly = (filename) => { |
|
const dateString = filename.replace('.md', '').replace('_year', '-01-01'); |
|
|
|
const date = moment(dateString); |
|
const year = date.format("YYYY"); |
|
const lastYear = moment(date).add(-1, 'year'); |
|
const lastYearFile = this.yearlyFile(date, lastYear); |
|
const nextYear = moment(date).add(1, 'year'); |
|
const nextYearFile = this.yearlyFile(date, nextYear); |
|
const header = `# Overview of ${year}\n` |
|
+ `[< ${lastYear.format("YYYY")}](${lastYearFile}) -- [${nextYear.format("YYYY")} >](${nextYearFile})`; |
|
|
|
const birthdays = {}; |
|
const contents = app.vault.adapter.fs.readFileSync(this.birthdayFile, "utf8"); |
|
const dates = JSON.parse(contents); |
|
|
|
for (const [MM, value] of Object.entries(dates)) { |
|
let list = ''; |
|
value.forEach(v => { |
|
if (v.year) { |
|
const diff = year - v.year; |
|
list += `- ${v.date}: ${v.text} (${diff})\n`; |
|
} else { |
|
list += `- ${v.date}: ${v.text}\n`; |
|
} |
|
}); |
|
birthdays[MM] = list; |
|
} |
|
|
|
return { |
|
year, |
|
header, |
|
birthdays |
|
} |
|
} |
|
|
|
this.monthOfYear = (year, i) => { |
|
let month = moment([year, i, 1]); |
|
return { |
|
month: month.format("MMMM"), |
|
monthFile: this.monthlyFile(month, month) |
|
} |
|
} |
|
|
|
this.filterLeftoverTasks = (line) => { |
|
return line.includes('- [ ] ') |
|
|| line.includes('- [>] ') |
|
|| line.includes('- [/] ') |
|
|| line.includes('- [R] '); |
|
} |
|
} |
|
|
|
} |