openpatch / hyperbook

Hyperbook is a quick and easy way to build interactive workbooks, that support modern standards and runs superfast.
https://hyperbook.openpatch.org
MIT License
29 stars 7 forks source link

Dynamic pagelist #857

Open jneug opened 5 months ago

jneug commented 5 months ago

For MediaWiki there exists an extension called DynamicPageList that can create lists of pages based on certain criteria and display them in different formats.

This could be used to add tables of content to pages or outlines of a subset of pages related to the current. Depending on the implemented feature set, it could create dynamic portal pages or category pages that group certain pages.

Proposed features

The most basic version could simply list all pages in a subdirectory of book:

:pagelist{dir="learning-path-python" order-by="index"}

gives something like

- [Was ist Python](learning-path-python/step1.md)
- [Erste Schritte](learning-path-python/step2.md)
- ...

This would be of limited use, though. The more filter criteria for page selection are available, the more powerful this gets:

Show all pages whose title starts with "Schuljahr 23/24: "
:pagelist{title="Schuljahr 23/34: %" order-by="title"}

Show all apges with the keyword "machine learning":
:pagelist{keyword="machine learning" order-by="created"}

The output format could be controlled by a parameter with predefined options:

Show all pages whose title starts with "Schuljahr 23/24: "
:pagelist{title="Schuljahr 23/34: %" order-by="title" format="table"}

Possible options:

This feature would be even more powerful when combined handlebars templates:

Show all pages whose title starts with "Schuljahr 23/24: "
:::pagelist{title="Schuljahr 23/34: %" order-by="title"}
### {{{ header }}}
{{#each pages}}
- [{{{ this.title }}}]({{ this.url }})
{{/each}}
:::
mikebarkmin commented 5 months ago

This is a great feature. For the handlebars templates, I would use a more "native" solution. Maybe something like this.

{{#each (pagelist title="Schuljahr 23/34: %" order-by="title") }}
- [{{{ name }}}]({{ path.href }})
{{/each}}
:::

And I think pagelist should return VFile-objects

https://github.com/openpatch/hyperbook/blob/51148b38ba46c2e2434353f0768c1ba592519512/packages/fs/src/vfile.ts#L9-L63.

jneug commented 5 months ago

Another possibility would be the use of snippets to get reusable formats.

In a page

:pagelist{... snippet="my-list-snippet"}

And in snippets/my-list-snippet.md.hbs:

{{#each pages}}
- {{{ title }}}
{{/each}}

Thats the way the MediaWiki extension does it.