Dynamic (Embedded) Link for today's Daily Note

What I’m trying to do

I wanted to put a note into a canvas, but I wanted that note to be whatever today’s daily note is.

I setup a note called “Today” (not sure I’ll stick with that name :stuck_out_tongue: ) and added that to the canvas. Next I’ve been trying to add a dynamic embedded link to the Today note.

I don’t think I can hack the Today note’s (or Daily Note’s) path in the .canvas file, hence trying to embed a constant “Today” note that used a dynamic embed, if you get what I mean.

Things I have tried

I’ve tried using Dataview to get a dynamic link to a daily note. So far that’s the only way I’ve successfully gotten a dynamic link. I’ve tried to use Dataview’s embed() function but that turns the link into plain text (the documentation notes this function doesn’t work well). I’ve tried to build the ![[]] notation in various ways inside of and around the inline dataview code but I’ve not gotten any combination to work yet.

The embed line I’ve used is =embed(link(dateformat(date(today), "yyyy-MM-dd")))

I was mostly using info this thread, this thread and the Dataview docs.

I think I’m near a dead end with the approach of using inline Dataview so I might need a totally different approach.

I’m very interested to see how other people do this. Here’s my solution:

![[2023-09-27 Wednesday]]%%embed%%

// Get the current file
const file = app.vault.getAbstractFileByPath(dv.current().file.path)
// Get the text contents of the current file
let contents = await app.vault.read(file)
// Update any text on the line before %%embed%% to be an embedded link to today's note
contents = contents.replace(/^.*?%%embed%%$/m, '![[' + moment().format('YYYY-MM-DD dddd') + ']]%%embed%%')
// Save the new contents back to the current file
await app.vault.modify(file, contents)

If you put this code in a note (including the first line), every time you visit that note the Dataview code will execute and update the embed link to be the current date.

I’ve tested this just now and it also works fine from a canvas, and automatically updates the embedded note just from viewing the canvas.

Note: You will need to update my date format YYYY-MM-DD dddd to match the one you’re using.


That solves my case perfectly, thanks.

As you’re also interested in other solutions I’ll hold off marking solved for a day or so incase anyone posts about something else.

1 Like

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