Navigation in Daily Journal with moment.js and Templater

What I’m trying to do

I’m stuck with the navigation bar in my daily notes. I’m basing myself on the template My Obsidian Daily Note Template | Dann Berg: blog, newsletter, shop, and more .

I started with the navigation bar < Yesterday | WK-46 | Tomorrow > . But while navigating through earlier notes, it is not always very clear to which page I’m going. So I adapted the formula and now the navigation bar looks like:
< 2022-11-17-Thursday | WK-46 | 2022-11-19-Saturday >

I would like to strip the day name in the navigation bar < 2022-11-17 | WK-46 | 2022-11-19 > while the filenames remain in the format “YYYY-MM-DD-dddd” and I’m not sure how I can achieve this result.

The following script line is working for printing a date in the format “YYYY-MM-DD-dddd”:
[[<% moment(tp.file.title, ‘YYYY-MM-DD-dddd’).subtract(1, ‘d’).format(“YYYY-MM-DD-dddd”) %>]]

But if I strip the format part to “YYYY-MM-DD”, the link is also changed to "YYYY-MM-DD and I prefer to keep my daily notes in the format “YYYY-MM-DD-dddd”.

With a fixed text ( “Yesterday” here ) it should be this:
[[<% fileDate = moment(tp.file.title, ‘YYYY-MM-DD-dddd’).subtract(1, ‘d’).format(‘YYYY-MM-DD-dddd’) %>|Yesterday]]

Is it possible to show a date “YYYY-MM-DD” while the filenames for the daily notes are in a different format? I can’t find any examples or help concerning this. This involves Templater and Moment.js .

[[ <%* tomorrow = moment(tp.file.title, 'YYYY-MM-DD-dddd').subtract(1, 'd').format("YYYY-MM-DD-dddd") 
   tR += `${tomorrow} | ${tomorrow.substring(0,10)} ` %>  ]] 

That’s the solution, and here comes the explanation. I’ve changed into a javascript execution style of Templater, by using <%*, this allows for more javascript constructs. In particular, it allows for me to store the result of your previous moment() call, using the const tomorrow = moment(...). This will make it a whole lot easier to output the result twice, and not only once.

Regarding the output, it’s changed to adding stuff to the tR variable, and we want to add three parts to the output. The link part, which now stored in tomorrow, the alias indicator |, and finally the alias which needs to be the first ten character of the link part, aka tomorrow.substring(0, 10). Put this together using template literals and it looks like: tR += ${tomorrow} | ${tomorrow.substring(0,10)} .

( And older variant of this could look like, tR += tomorrow + ’ | ’ + tomorrow.substring(0, 10), but I prefer the newer style. :slight_smile: )

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.