pietroppeter / nimibook

A port of mdbook to nim(ib)
https://pietroppeter.github.io/nimibook/
MIT License
77 stars 7 forks source link

Allow sections to be collapsed/expanded with a chevron-icon button #79

Open PhilippMDoerner opened 1 year ago

PhilippMDoerner commented 1 year ago

The Feature Suggestion

Allow the entries in the sidebar to be "folded in" and "out".

Motivation for this feature

Take this sidebar: image

This is likely to grow in the future, making visibility of points below "internals" (and future longer sections) difficult.

It would be nice if I could "fold in" entries of the sidebar so that it can look more like this: image

I would suggest this provide the following features:

1. Expand/Collapse on click icon - button

Every section is not just a hyperlink. To the left or right of the section entry in the sidebar should be an icon-button that a user could click on to expand/collapse a section of entries. For a consistent design language, the icons used should likely be chevron icons to indicate that it is currently collapsed (chevron-up) or expanded (chevron down).

The button should highlight on hover separate from the section-hyperlink.

2. Automatically expand section when user is in an entry of that section

In this example: If I am on the page "Build Hook", I would expect the section "Internals" and "Hooks" to be expanded, but not "Adders"

3. Side-consideration: Remove sections having their own pages and make their sole purpose to expand/collapse sections

It may be worth considering maybe making sections no longer their own page but only buttons to expand/collapse sections of a sidebar. That would be a breaking change.

Alternatively, it could be considered to keep section as is and introduce a new grouping mechanism going by the name of group, that you just pass the name it should have on the sidebar and whether the group should be expanded/collapsed initially.

pietroppeter commented 1 year ago

as nimibook is in its essence a port of mdbook the first place to look at is if this is implemented in mdbook. From a quick search it appears it is indeed available: https://rust-lang.github.io/mdBook/format/configuration/renderers.html#outputhtmlfold

I have not yet checked how it is implemented in the code (and when it was implemented, we might need to catch up on the templates). It would also be nice to see a real example on how this implementation looks like when it is active.

pietroppeter commented 1 year ago

it appears it was implemented here in mdbook: https://github.com/rust-lang/mdBook/pull/1027 since was before the moment nimibook was born, we might already have the feature hidden somewhere :)

anyway thanks for the input! I think it could be nice, not planning to work on this at the moment, but happy to help if someone wants to give it a try.