Created
January 23, 2022 01:51
-
-
Save zachdaniel/29510d7c0c1fd0f87cc9a28bb783fd75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let habits = new Set(); | |
const linksToHabits = {}; | |
let days = []; | |
function compareName(a, b) { | |
if (a.file.name < b.file.name) { | |
return -1; | |
} | |
if (a.file.name > b.file.name) { | |
return 1; | |
} | |
return 0; | |
} | |
function titleCase(string) { | |
return string.split('-').map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(" "); | |
} | |
function toHabitValue(value) { | |
if(value === true) return "✅" | |
if(value === false) return "❌" | |
if(typeof value === "undefined") return "❌" | |
return value; | |
} | |
[...dv.pages("#2022-03")] | |
.sort(compareName) | |
.forEach((p) => { | |
const date = new Date(p.file.name + " 00:00"); | |
// can't do links in table headers? | |
// const fileLink = new Link({path: p.file.link.path, embed: false, display: | |
// date.toLocaleDateString('en-US', { weekday: 'long' }) | |
// }); | |
days.push(date.toLocaleDateString('en-US', { weekday: 'long' })); | |
const link = p.file.link; | |
Object.keys(p.habits || {}).forEach(habit => { | |
habits.add(habit); | |
linksToHabits[habit] = p.habits[habit]; | |
}) | |
}) | |
habits = [...habits].sort(); | |
const rows = habits.map((habit) => { | |
const days = [...dv.pages("#2022-03")] | |
.sort(compareName) | |
.map((f) => { | |
return toHabitValue((f.habits || {})[habit]); | |
}); | |
return [titleCase(habit)].concat([...days]); | |
}) | |
console.log(days) | |
console.log(rows) | |
dv.table(["Habit"].concat(days), rows); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment