What I’m trying to do
I’m trying to tweak my Daily Note template (using Templater) and I’ve written a user script for getting the last created file for a Previous link, but the Next link defaults to tomorrow and I want to be able to update that when a new daily note is generated and tries to update its own Previous link. The need is because I don’t use the daily note every single day and I want the daily note links for Previous/Next to target the equivalent previous/next file in the folder, going by creation date.
Things I have tried
const last_created_metadata = app.metadataCache.getFileCache(last_created);
const last_created_links = last_created_metadata?.links;
if(last_created_links && last_created_links.length > 0)
{
last_created_next_link = last_created_links.find(x=> x.displayText.includes("Next"));
if(last_created_next_link){
console.log("Found last_created Next link: "+last_created_next_link.displayText);
const link = app.fileManager.generateMarkdownLink(tp.config.target_file, tp.file.folder(true), ...[, ], last_created_next_link.displayText);
last_created_next_link.link = link;
last_created_next_link.original = "[["+link+"|Next >]]";
}
}
Currently this is what I have. In the function that basically finds the last_created TFile in the Daily Notes folder (excluding the one we’re currently generating), gets its links through its cached metadata and tries to update the underlying link.
The template file’s links are defined like so:
[[<%tp.user.find_last_daily_note(tp)%>|< Previous ]] - [[<%tp.date.tomorrow("YYYY-MM-DD")%>|Next >]]
Not sure I’m even doing this correctly. Any ideas?