How to match all pages under `/Dailies/`?

Hi.

Coming from Journal previous day and next day navigation - Tricks & Techniques - SilverBullet Community. I want to port it to my layout.

Mine layout is:

  • /Dailies/<year>/<month>/<day>

So today would be /Dailies/2025/01/29.

I have tried several pattern, none of them work.

hooks.top.where: 'name =~ /^Dailies/'  # only works for top level `/Dailies` page
hooks.top.where: 'name =~ /^Dailies\/.+\/.+\/.+$/' # doesn't work
hooks.top.where: 'name =~ /^Dailies\/\d{4}\/\d{2}\/\d{2}$/' # doesn't work

Any suggestions?

Thanks!

Hi there,

Sorry you’re having difficulties.

The problem doesn’t seem to be the pattern - hooks.top.where: 'name =~ /^Dailies/' works fine for me as the way to match the pages.

But when it comes to figuring out the date from the page URL, it fails. The code is simplistic, and based on the assumption that ‘the last bit after the slash is the date in string form’. That’s not true in your new case (the code tries to parse ‘29’ as an entire date today).

As a quick (very inelegant) fix you could replace the space-script line:

const date = parts[parts.length - 1];

with:

const date = '' + parts[parts.length - 3] + '-' + parts[parts.length - 2] + '-' + parts[parts.length - 1];

and that should get you up and running, or at least give you a better place to start.

Hope this helps,

Geoff

Your hooks worked for me…

hooks.top.where: 'name =~ /^Dailies/'  # Worked on all levels
hooks.top.where: 'name =~ /^Dailies\/.+\/.+\/.+$/' # Worked on ONLY the "Dailies/<year>/<month>/<day>" pages
hooks.top.where: 'name =~ /^Dailies\/\d{4}\/\d{2}\/\d{2}$/' # Worked on ONLY the "Dailies/<year>/<month>/<day>" pages

I have this widget template:

---
description: test widget
tags: template
hooks.top.where: 'name =~ /^Dailies/'
---
# TEST WIDGET
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
(expand for images)



So I think something else may be going on, can you post what you have added for your widget template and space-scripts to see if there is anything in the modifications you would have had to make to @OpinionatedGeek’s templates/scripts that may be causing issues?

hooks.top.where: 'name =~ /^Dailies/' isn’t working for me, so I believe the issue lies in the code, just as you suspected.

JournalNavigationTemplate

---
description: Adds navigation to journal pages.
tags: template
hooks.top.where: 'name =~ /^Dailies/'
---

```template
[[{{newJournalFromCurrentPage(@page.name, -1)}}|⬅️ Previous]] | 📅 | [[{{newJournalFromCurrentPage(@page.name, 1)}}|Next ➡️]]
```

Script


```space-script
silverbullet.registerFunction({name: "newJournalFromCurrentPage"}, (pageName, offsetDay) => {
    // pageName: 'Dailies/2025/01/27'
  const parts = pageName.split("/"); // ["Dailies", "2025", "01", "27"]
  const dateParts = parts.slice(1); // ["2025", "01", "27"]
  const isoDate = dateParts.join("-"); // "2025-01-27"
  const date = Temporal.PlainDate.from(isoDate); // Temportal date object
  // Apply the offset (e.g., -1 or +1 days)
  const offsetDate = date.add(Temporal.Duration.from({ days: Number(offsetDay) }));
  // Initialize pageTarget with the base part of the page: ["Dailies"]
  const pageTarget = parts.slice(0, 1);
  // Add the adjusted date in the desired format: 2025/01/27
  pageTarget.push(offsetDate.toString().replace(/-/g, "/"));
  return pageTarget.join("/"); // "Dailies/2025/01/27"
});
```

I tried to change to client mode. It works for a while, then it doesn’t.
Strange behavior.

I have checked the code, using node REPL in my terminal and the console on browser. It works fine.

Sometimes I need to hit refresh multiple times for widget to appears, but sometimes it just doesn’t work. I see no errors on the log.

What exactly is not working?
The code indeed looks fine. Is the link not appearing or is the link not working?

Did you try putting some console.log’s in between?

Did you try putting some console.log’s in between?

The console.log never gets printed.

Is the link not appearing or is the link not working?

The links appear on the intended page if I just put return "".
But with the code above, it doesn’t appears.