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

Make auto-generated multiple sidebars exclusive by default #10500

Closed
5 of 7 tasks
cseas opened this issue Sep 13, 2024 · 1 comment
Closed
5 of 7 tasks

Make auto-generated multiple sidebars exclusive by default #10500

cseas opened this issue Sep 13, 2024 · 1 comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@cseas
Copy link

cseas commented Sep 13, 2024

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

I'm trying to use the "Multiple Sidebars" feature since I have two categories in my documentation.
The documentation doesn't mention anything about this feature not working properly with auto-generated sidebars:
https://docusaurus.io/docs/sidebar/multiple-sidebars

When multiple autogenerated sidebars are defined, it should be default behaviour that the directories of the new sidebars should be excluded from the main first sidebar generated from the docs directory.

Screenshot 2024-09-13 at 5 33 14 PM

It could be argued that the same behaviour could be achieved with an exclude option as discussed in #5689 (comment) but the way the documentation is defined, the impression is that multiple sidebars will be exclusive by default. If not, then it should be documented that explicitly defining the structure of docs is necessary to omit certain directories generated as a separate sidebar as done in Docusaurus website as well.

Reproducible demo

https://codesandbox.io/p/sandbox/young-wood-5k56n7

Steps to reproduce

Define a new sidebar:

// sidebars.ts

const sidebars: SidebarsConfig = {
  tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
  api: [{type: 'autogenerated', dirName: 'api'}]
};

And then in docusaurus.config.ts, add the following to navbar.items:

        {
          type: 'docSidebar',
          position: 'left',
          sidebarId: 'api',
          label: 'API',
        },

This does generate a new link on the header with "API" label and a sidebar as expected. The problem is that the same sidebar still appears nested inside of the main "Docs" sidebar.

Expected behavior

The api directory should get excluded from the main Docs sidebar as there's a separate sidebar defined for it.

Actual behavior

The api directory is both generated as a separate sidebar and appears nested inside of the Docs sidebar.

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@cseas cseas added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Sep 13, 2024
@slorber
Copy link
Collaborator

slorber commented Sep 13, 2024

There is no concept of "mutually exclusive"

Docusaurus lets you assemble "autogenerated sidebar slices" in various ways and doesn't do any filtering magic. If you add a sidebar slice to one sidebar, it doesn't make it disappear from another sidebar. You can add the same sidebar slice to 2 sidebars and expect the items to appear in both places.

If you want mutually exclusive autogenerated sidebars, then you'd rather create a docs/tutorial and docs/api folder. If you consider . to generate your tutorial sidebar, there's no reason to put the api folder there because you don't want to appear in your tutorial sidebar. You can solve this problem by using a dedicated folder for each sidebar, instead of having one sidebar inside another.

@slorber slorber closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2024
@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution
Projects
None yet
Development

No branches or pull requests

2 participants