How to automatically generate a link to a record for the most recent date

Problems encountered

My diary is named with a date. When using Templater and journal templates, I can automatically create a new journal link for the previous day with the help of <% tp.date.now(“YYYY MM month DD day”, -1, tp.file.title, “YYYY year MM month DD day”). If the journal is not continuous, can I automatically create a journal link for the most recent record?

Expected effect

When I create a new journal using a template, a link to the journal record that is closest to the date has been automatically established .

One way of tackling this issue is to create a dv.view() which scans the folder by date (or file.day), and presents the chosen candidates. This will also have the added benefit of changing the links if you insert new entries in retrospect.

The template would then only the link to the dv.view().

Thanks! The solution offered by a well-meaning person is as follows.

<%*

let dv = DataviewAPI;
let file = dv.pages(PATH)
.filter(p => moment(p.file.name).isValid() && moment(p.file.name) != moment().format(“YYYY-MM-DD”))
.sort(p => p.file.name,‘desc’)[0]
let previous = file.file.name

-%>

[[<% previous %>]]

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