I have a bunch of notes for different projects, and in each of them I have sort of a date-based log. If I work on 3 different projects in one day, all 3 project notes will get a date header (or list item) with the same date in the same format.
Something like this:
proj a:
- #devlog
- date 1
- did this
- and this
- date 2
- did that
proj b:
- #devlog
- date 1
- did those
I’d like to use dataview to generate a devlog note that has all my dev log entries grouped by date, then by project, to get a sort of grand devlog without having to maintain a big long note. Like such:
devlog:
- date 1
- proj a
- did this
- and this
- proj b
- did those
- date 2
- proj a
- did that
You can probably tell by my weird use of a top level list item with just #devlog that I found lists to be almost what I needed to do to achieve this. But after a few hours of messing around with the query language I just couldn’t achieve what I’m looking for. I’m thinking it will require some nested group bys or something. I’m also okay with having some vestigial stuff in the output like the #devlog parent, maybe as a task if that makes the query somehow easier.
Unsurprisingly, I found the best solution to be JavaScript (rather, dataviewjs).
Here’s what my query looks like, and it does exactly what I want it to (with the source entries structured exactly as in the original post, with the #devlog “parent” list item. It just seems to me to be the easiest way to accomplish this):
let devlog = {}
for (let page of dv.pages("#devlog")) {
if (page.file.lists) {
for (let loglist of page.file.lists.filter(l => l.text.includes("#devlog"))) {
for (let entryDate of loglist.children) {
if (!devlog[entryDate.text]) {
devlog[entryDate.text] = {}
}
devlog[entryDate.text][page.file.link] = entryDate.children
}
}
}
}
for (const entryDate of Object.keys(devlog).sort().reverse()) {
dv.header(2, entryDate)
for (const proj of Object.keys(devlog[entryDate]).sort()) {
dv.taskList(devlog[entryDate][proj])
}
}
I utilize dv.taskList to handle all nested list items (should I want them) and because it automatically groups by file name at the level that I want it to, as well as providing clickable backlinks to all individual list items. Very neat and perfect in this use case.