Last active
February 16, 2023 20:46
-
-
Save WebInspectInc/d0fb466cbe87778255b188f3508a52bd to your computer and use it in GitHub Desktop.
A Dataview script for displaying an "On this Day" feature in Obsidian. Read more here: https://obsidian.rocks/supercharge-your-daily-notes-in-obsidian/
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
```dataviewjs | |
// update path and minyear if needed | |
const journalPath = 'Journal/Daily'; | |
const minYear = 2012; | |
const d = new Date(); | |
const rangeOfYears = (start, end) => Array(end - start + 1) .fill(start).map((year, index) => year + index); | |
const availableYears = rangeOfYears(minYear, d.getYear() + 1900); | |
const month = ("0" + (d.getMonth() + 1)).slice(-2); | |
const day = ("0" + (d.getDate())).slice(-2); | |
const dateString = month + '-' + day; | |
availableYears.forEach((y) => { | |
// you may also have to update this date string, if your files aren't formatted in the default way (YYYY-MM-DD) | |
var note = dv.page(`${journalPath}/${dateString}-${y}`); | |
if (note) { | |
dv.el('span', `[[${note.file.path}|${y}]] `); | |
} | |
}); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using in the daily note files directly:
To have this in historic files as well and not bound to the current date, we can use:
This will return the current file name, which we can use to extract month + day to then look up differnt years.