Breadcrumbs for hierarchical pages

Hi!

I like to structure my pages in an hierarchical way and wanted to see the current nesting / “breadcrumbs”. I added a Template Widget and some space script for it, see below in case anyone else is interested. Happy to hear any comments or suggestions!

---
description: Adds breadcrumbs to pages
tags: template
hooks.top.where: 'true'
---
[[index]] > {{#each getSuperPaths(@page.name)}}[[{{.}}]] > {{/each}}{{getChildPageName(@page.name)}}
Child pages:
{{#if @page.name = "index"}}
```query
page where name =~ "^[^/]+$" render [[Library/Core/Query/Page]]
```
{{else}}
```query
page where name =~ "^" + @page.name + "/[^/]+$" render [[Library/Core/Query/Page]]
```
{{/if}}
```space-script
silverbullet.registerFunction({name: "getSuperPaths"}, (name) => {
  const nameComponents = name.split('/');
  const superPaths = [];
  for (let i = 0; i < nameComponents.length-1; i++) {
    const path = nameComponents.slice(0, i+1).join('/');
    superPaths.push(path);
  }
  return superPaths;
});

silverbullet.registerFunction({name: "getChildPageName"}, (name) => {
  const nameComponents = name.split('/');
  if (nameComponents.length < 1) {
    return "";
  } else {
    return nameComponents.at(-1)
  }
});
```
````
14 Likes