What I’m trying to do
I’d like to set up links at the top of my daily note template so that I can navigate to:
- the previous existing daily note (which would not necessarily be the previous day’s, if I’ve skipped a number of days),
- the next (existing) note,
- and the weekly note for the corresponding week
Of note, I’m using the following date format in the Daily Notes plugin so that notes live in nested folders (I read that the format field accepts paths): YYYY/MM-MMMM/YYYY-MM-DD
(i.e. 2023 > 01-January). Potentially relevant because the nesting seems to be throwing off the command to open the previous/next daily note… after I switched to this date format, these options no longer appear in the command palette.
Things I have tried
I’ve been trying to follow this reddit post and the updated method in this comment.
I have the following at the top of my daily note template:
<% tp.user.daily_prev() %> | [[{{date:gggg/gggg-[W]ww}}|Week]] | <% tp.user.daily_next() %>
In the Templater plugin, I’ve enabled “User System Command Functions.”
Function #1 - daily_prev
:
daily_notes_path="$(pwd)/Notes - Daily"
prev_format="Previous"
prev_note="$(/bin/ls "${daily_notes_path}" | tail -n2 | head -n1 | cut -f 1 -d '.')"
echo "[[${prev_note}|$prev_format]]"
Function #2 - daily_next
:
daily_notes_path="$(pwd)/Notes - Daily"
next_format="Next"
prev_note="$(/bin/ls $daily_notes_path | tail -n2 | head -n1)" sed -i "" "s/${next_format}/[[<% tp.file.title %>|${next_format}]]/g" "${daily_notes_path}/${prev_note}"
echo $next_format
(According to the original reddit post, once the daily note is created, it not just links to the next most recent note, but it should also modify the “Next” link in that previous note to point to your current post, which is pretty cool.)
But the links don’t work as intended… for example, when I click on “Previous” in today’s daily note, instead of taking me to the previous daily note from two days ago, it creates a new note titled “2023” (nested in the folders: Daily Notes folder > 2023 > 11-November > 2023.md)
I have a feeling it’s not working because of my nested date format. How can I alter the functions to take this into account and create workable links?
Thank you in advance!