web-infra-dev / rspress

🦀💨 A fast Rspack-based static site generator.
https://rspress.dev
MIT License
1.36k stars 120 forks source link

[Bug]: auto sidebar does not deal with intermediate bare sub-directories gracefully #1199

Open superwushu opened 3 months ago

superwushu commented 3 months ago

Version

v1.25.0

Details

Auto sidebar works well with typical directory hierarchy in which each level having valid content files and _meta.json. But in some cases, we use bare intermediate sub-directory levels for namespace organization in cases of submenu in navbar, e.g.

doc
|-- aaa
    |-- bbb
        |-- ccc
            |-- _meta.json
            |-- overview.md

Intermediate directories bbb and ccc are bare. The expectation is the sidebar generated for overview.md has a flat structure with the file title as the root. But the current behavior is the sidebar shows all levels of aaa/bbb/ccc and place the file title to deep bottom, very annoying in looking.

A workaround is to use themeConfig rather than auto sidebar.

But I think a reasonable solution is to skip directory levels without the _meta.json file, or introduce a new option to _meta.json file to skip specified levels. Any thoughts?

Reproduce link

see above

Reproduce Steps

see above

Timeless0911 commented 3 months ago

But the current behavior is the sidebar shows all levels of aaa/bbb/ccc and place the file title to deep bottom, very annoying in looking.

I don't think it is annoying, on the contrary I think this is as expected as we design.

The sidebar generation of Rspress is based on the conventional routing of the file directory. We will perform some automatic detection operations. The middle level bbb and ccc should be displayed in the sidebar.

In other words, in the automatic detection scenario, the file directory should truly reflect the level of the sidebar.

In your case, it is recommended to use a custom configuration sidebar array in themeConfig.

superwushu commented 3 months ago

The sidebar generation of Rspress is based on the conventional routing of the file directory. We will perform some automatic detection operations. The middle level bbb and ccc should be displayed in the sidebar.

In other words, in the automatic detection scenario, the file directory should truly reflect the level of the sidebar.

My understanding is auto detection is based on the existence of _meta.json. If a directory has no _meta.json the sidebar info is read from themeConfig. For intermediate directories that neither have _meta.json or configured in themeConfig, they are not supposed to reflect in sidebar.

But if it's designed to be that, I'm okay.

Timeless0911 commented 3 months ago

My understanding is auto detection is based on the existence of _meta.json. If a directory has no _meta.json the sidebar info is read from themeConfig.

The designed specific sidebar generation logic is