Create a dataviewjs snippet returning a string that will contain all distinct tags included in my daily notes (named YYYY-MM-DD) from the current week.
example: if today’s date is 2023-12-08 and:
note 2023-11-30: (that is not in the current week) #tagN #tagZ #tag6
note 2023-12-04: #tag1 #tag2 #tag3
note 2023-12-05: #tag1 #tag4 #tag3
note 2023-12-06: #tag2 #tag5 #tag7
The snippet embeded in a week recap note should display the string:
#tag1#tag2#tag3#tag4#tag5#tag7
Things I have tried
To start with, I tried this snippet that is supposed to return distinct tags from a folder
let tags = []
for (let tag of dv.pages('ObsiLog/journals').file.tags) {
if (tags.indexOf(tag) == -1) {
tags.push(tag)
}
}
dv.list(tags)
but I get an error on the path to my journals folder where my daily notes are whether I use:
‘ObsiLog/journals’
‘/ObsiLog/journals’
‘/journals’
‘journals’’
Once working, it will needs to be tweaked to only push tags from the files’ week: if looking at a note from week 12, I only want to show the tags from that week in particular
Note that file.day gets it value either of properly formatted date in the file name, as in your case, or from a date property within the file (allowing for filenames to either use localised dates or no date at all).
So redoing your unique tags code, combined with this week code, we could arrive at something like the following:
```dataviewjs
// Define some helper variables
const currentWeek = moment().format("yyyy-W")
const uniqueTags = {} // Using a set, which never adds a key twice...
// Loop through this weeks list of tags
dv.pages('"journals"')
.where(p => p.file.day)
.where(p => moment(p.file.day.toISODate()).format("yyyy-W") == currentWeek )
.file.etags
.forEach(t => uniqueTags[t] = true) // The value doesn't really matter
// Display the unique list of tags
dv.paragraph(Object.keys(uniqueTags).join(" "))
```
I just need the week number from the file name, not the moment
I want to be able to look back at a note from 3 months ago and see the tags from that week
So I would need some help on changing:
const currentWeek = moment().format(“yyyy-W”)
to something like
const fileWeek = dv.current().file.name.toISODate().format(“yyyy-W”)