silverbullet icon indicating copy to clipboard operation
silverbullet copied to clipboard

Feature Request: Virtual Pages

Open schroederc opened this issue 1 year ago • 3 comments

Generalize https://github.com/silverbulletmd/silverbullet/blob/main/plugs/index/tag_page.ts to any number of “virtual” pages.

Instead of 📌 {{tag}} pages being specially handled, have a general mechanism for rendering read-only pages derived from a template.

My suggestion would be to add a new field to Page Templates to optionally denote it as “virtual”:

---
description: "Index of tagged objects"
tags: template
hooks.newPage:
  forPrefix: "Tag/"
  virtual: true
---

These are all objects in your space tagged with #{{replace(@page.name, "Tag/", "")}}.
```template
template: |
    {{#if .}}
    # Pages
    {{#each .}}
    * [[{{name}}]]
    {{/each}}
    {{/if}}
query: |
    page where tags = {{replace(@page.name, "Tag/", "")}}
```.

When a user opens such a page, its template is rendered in a read-only fashion and the title can be consumed to vary its contents like for the above simplified tag index page.

Along with allowing the template for tag pages to be customized by the user with this feature (by moving the template into the Core library), it allows some use-cases such as having virtual Weekly Note pages that summarize each week, having index pages for a prefix (like a Person/ index), or interesting pages like Journal/Tasks/2024-02-29:

---
description: "Index of tasks for a day (inbox + journal)"
tags: template
hooks.newPage:
  forPrefix: "Journal/Tasks/"
  virtual: true
---

```template
template: |
  {{escape "#each ."}}
  * [[{{escape "state"}}]] [[{{escape "ref"}}]] {{escape "name"}}
  {{escape "/each"}}
query: |
  task where page =~ /\Journal\/Day\/{{replace(@page.name, "Journal/Tasks/", "")}}/ or page =~ /^Inbox\/{{replace(@page.name, "Journal/Tasks/", "")}} /
```.

An important aspect of this feature is that the pages are not reified which means that we can alter the template to alter all instances of the virtual page at any point and we don't litter our Space with many copies of essentially the same contents. They also act like the existing tag pages which means they are read-only and the rendered templates aren’t expandable (for easier readability).

schroederc avatar Feb 29 '24 21:02 schroederc

This is a great suggestion.

Would essentially solve my problem: https://github.com/silverbulletmd/silverbullet/issues/743#issuecomment-1961320973

henrikx avatar Mar 01 '24 11:03 henrikx

+1 this would be awesome

devzero avatar Mar 01 '24 11:03 devzero

Also see: https://community.silverbullet.md/t/virtual-page-templates/96

zefhemel avatar Mar 02 '24 06:03 zefhemel