Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Excluded routes still appear in the no-config sidebars #848

Open
Tyneor opened this issue Mar 22, 2024 · 3 comments
Open

[Bug]: Excluded routes still appear in the no-config sidebars #848

Tyneor opened this issue Mar 22, 2024 · 3 comments
Labels
🐞 bug Something isn't working

Comments

@Tyneor
Copy link

Tyneor commented Mar 22, 2024

Version

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz
    Memory: 2.99 GB / 15.69 GB
  Browsers:
    Chrome: 121.0.6167.185
    Edge: Chromium (122.0.2365.92)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    rspress: ^1.0.0 => 1.15.1

Details

I added the following lines to the rspress.config.ts :

route: {
    exclude: ["assets/**/*", "**/4-ignore.*"],
  },

expecting all assets in /docs and the 4-ignore.md not to have routes created for them and not appear in sidebars.

The routes are indeed not created but they still appear in the sidebar:

image

I don't really know if this is a bug but I would say that no-config sidebars should not display non-existing pages.

Reproduce link

https://codesandbox.io/p/devbox/minimal-route-exclude-in-sidebar-reproduction-gwzr65?file=%2Frspress.config.ts

Reproduce Steps

  1. remove _meta.jsonin docs/guide
  2. add assets in docs/guide/assets/
  3. add some markdown files in /docs/guide including 4-ignore.md
  4. in rspress.config.ts add
route: {
    exclude: ["assets/**/*", "**/4-ignore.*"],
  },
  1. the assets and the Ignore route still appear in the guide sidebar
@Tyneor Tyneor added the 🐞 bug Something isn't working label Mar 22, 2024
@Tyneor
Copy link
Author

Tyneor commented Mar 25, 2024

I found a way to exclude the excluded route from the no-config sidebar.

I can work on a pull request if necessary but since I'm not sure that it is considered a bug or a feature that could be added to pluginAutoNavSidebar I will write my code here:

I replaced the following code:

const subItems = await fs.readdir(workDir);

with one of those:

// can ignore assets/**/* because it doesn't direcly match directories, it only matches files and route.exclude is supposed to target files
const includedFiles = globby.sync(`**`, { cwd: workDir, ignore: [...exclude] });
const subItems = Array.from(new Set(includedFiles.map((file) => file.split("/")[0])));
  // can only ignore assets/** because it only matches direct children
  const subItems = globby.sync(`*`, { cwd: workDir, onlyFiles: false, ignore: [...exclude] });

globby comes from import globby from "globby"; and exclude comes from config.route.exclude

Side note
I also had to add sidebar: {} in the themeConfig to force my plugins: [pluginAutoNavSidebar()] to register the plugin.
Maybe user defined plugins should take precedence over plugins added automatically?

@10Derozan
Copy link
Member

Yes, you are right. When fallback to readdir, we need add exclude. Welcome PR

@10Derozan
Copy link
Member

Reply to your side note:
config hooks can not determine the order, maybe you need to add sidebar to avoid internal plugin.

Tyneor added a commit to Tyneor/rspress that referenced this issue Apr 2, 2024
Tyneor added a commit to Tyneor/rspress that referenced this issue Apr 2, 2024
…ion, fixed globby import, fixed empty folder appearing in sidebars, fixed changeset
Tyneor added a commit to Tyneor/rspress that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants