I use the Journal plug, and it’s neat! I wanted to be able to easily navigate from one day’s entry to the previous or next, and there wasn’t anything out-of-the-box. It was pretty simple to add though.
This script and template will put something like the following (with working links) at the top of each Journal page (only Journal pages - other pages are left alone).
Previous | Journal/Day/2024-10-27 | Next
‘Previous’ takes you to the previous day, and clicking ‘Previous’ on that page will take you to the day before, and so on. It’s possible to navigate back days and weeks using this, which I find useful sometimes if I don’t know which particular day’s notes I want.
Here’s what worked for me. You need to create 2 new pages, but it doesn’t matter much where you put them. (I have mine in Custom/Extensions
).
- Create a new page for the
space script
(I called mineJournalNavigationScript
) and add the following:
```space-script
silverbullet.registerFunction({name: "newJournalNameFromExistingJournalName"}, (page, days) => {
const parts = page.split("/");
const date = parts[parts.length - 1];
const plainDate = Temporal.PlainDate.from(date);
const offsetDate = plainDate.add(Temporal.Duration.from({ days: Number(days) }));
const result = parts.slice(0, -1);
result.push(offsetDate.toString());
return result.join("/");
});
(Not rendered here - three backticks to close the script.)
- Create a new page for the template (I called mine
JournalNavigationTemplate
) and add the following frontmatter and template:
---
description: Adds Journal navigation to journal pages.
tags: template
hooks.top.where: 'name =~ /^Journal\/Day/'
---
```template
[[{{newJournalNameFromExistingJournalName(@page.name, -1)}}|⬅️ Previous]] | [[{{@page.name}}|📅 {{@page.name}}]] | [[{{newJournalNameFromExistingJournalName(@page.name, 1)}}|Next ➡️]]
(Not rendered here - three backticks to close the template.)
The frontmatter and template does need to be on a page on its own, but the script can go on a page with other scripts if you prefer.