Repository navigation
Description
🚀 Feature
Several things:
- Add
excludeoption in category metadata to filter out docs; - Add
additionalItemsoption to include more items in autogenerated categories, includinglink,ref, etc.; - Exclude entire subdirectories when declaring autogenerated sidebar items.
Have you read the Contributing Guidelines on issues?
Yes
Has this been requested on Canny?
No, but there are inline comments asking if they should be allowed, and the answer is yes: I've been asked about this feature.
Motivation
Sometimes we want a fully autogenerated sidebar, but occasionally want to add a few external links in categories. Sometimes we have a legacy directory structure and we only want to generate the sidebar from part of that directory.
API Design
In _category_.json, add the following options:
type CategoryMetadatasFile = {
label?: string;
position?: number;
collapsed?: boolean;
collapsible?: boolean;
className?: string;
+ additionalItems?: WithPosition<SidebarItem>[];
+ exclude?: {
+ paths: string[];
+ docIDs?: string[];
+ };
};paths accepts folder paths (I don't know if file paths would work well; from my experience with the autogenerator code, seems it's not easy since the doc metadata only includes sourceDir?), while docIDs accepts... doc IDs. It's assumed that the members in these two arrays are otherwise included in the category; if they are never included (non-existent IDs/paths not in the autogen dir...), maybe throw an error, or maybe do nothing.
additionalItems accepts doc, ref, link, and even category, but not autogenerated (at least I think it doesn't make much sense, and opens up holes to infinite recursion). Because doc items already come with their own sidebarPosition, they will be sorted well with the rest of the items. However, all items can have an additional sidebarPosition attribute (hence WithPosition<SidebarItem>) to override this behavior.
The autogenerated sidebar item will also accept the exclude and additionalItems properties, because the metadata file in the autogen dir root is not read.
Have you tried building it?
No
Activity
slorber commentedon Oct 12, 2021
I'd like to include more options yes, however this API design is not so simple and I'm not very fan of your current proposal 😅
The API you propose seems influenced by the current implementation details, which IMHO are not great and should be refactored first. Would you design this API the same if autogen sidebars were not implemented?
The last time I thought about it, my idea what just to have an
itemsattribute in_category_.jsonand it would allow to completely override the autogen for this specific dir for which you would need to be exhaustive, and it wouldn't attempt to more clever things like include/exclude/additional/merge. This may help delay the need for more powerful APIs and could be good enough or at least will give us the opportunity to understand user use-cases better.Josh-Cena commentedon Oct 13, 2021
Hard to say now I do know what's going on behind the scenes:P But even before I went down that rabbit hole, I was hoping for an
includeandexcludeglob pattern; and in order for that to be extensible to links, I changedincludetoadditionalItems. Hence this proposal.What if I want some additional links but keep the rest of the 10 categories + 50 doc links auto generated?
slorber commentedon Oct 13, 2021
If we could make the sidebar generation logic more recursive it would allow overriding some behavior on a per-category level more easily.
You can still generate the autogenerated sidebar, and modify/filter it after generation (ie remove subitems, add link in-between 2 existing items etc...).
This is a bit verbose to do for the end-user though. Maybe we should just expose some additional hooks or sidebar modification API, encapsulating the traversal logic?
A powerful API could be to let user add any kind of useful metadata in
_category_.jsonand provide some callbacks likeprocessCategoryin the generation logic where the user could read the metadata and add/filter the category items accordingly: the user can creates his own API that suits the use-caseJosh-Cena commentedon Oct 13, 2021
My mind always explodes when I work on recursion in our sidebar structure :P E.g. do we process the category's children prior to processing itself?
I'll revisit this proposal later since we recently have/will have quite a few changes with the sidebar architecture. Maybe category metadata would be read ahead of time. After a few weeks we may be in a better position to think about the API
slorber commentedon Oct 13, 2021
Yes, that's also what I think. An empty folder with a
_category_.jsonshould probably lead to an empty sidebar category (on which you could add extra links?), but with the current algorithm, it doesn't because there's no doc in this folder and we use doc's paths to infer the sidebar structures.I figured out the algo impl was not very good a bit later, but as the feature was already working correctly and the public API was fine I shipped it.
Refactoring this algo remains needed 🤯 so that we are more comfortable improving the autogen logic.
lorenzolewis commentedon Jan 20, 2022
Keeping an eye on this one. Just to help with my understanding:
index.mdfileexcludeoption (or something similar) to the autogenerated sidebar object to exclude thatindex.mdfrom being rendered as a child link.Referencing tauri-apps/tauri-docs#347
slorber commentedon Jan 20, 2022
@lorenzolewis that looks like a similar case to #5830 (comment) (except your doc is named
index)You should be able to do something like:
Eventually, we could figure a way to exclude it automatically, as it looks like a convenient default
We could also allow an include option so that you can generate the sidebar slice one level upper:
Does it make sense?
lorenzolewis commentedon Jan 20, 2022
@slorber makes perfect sense, thanks!
KatherineWhan commentedon Jan 20, 2022
@slorber I like the idea of being able to add docs too.
I have just had a read through the whole issue. Will there be any way to sort the sidebar items other than using position in the
_category_.json? Ideally sidebar_label alpha would be perfect by default!I have a workflow where kb articles will be scraped into my repo from up to 20 'source' repos and deposited into the kb folder. It is impossible to get the sidebar_position right and the current default sort is filename alpha which creates 'interesting results' as we have no control over how the teams name their files.
slorber commentedon Jan 21, 2022
Add docs where?
I don't understand what
kbis and what you mean exactly herePlease give a very concrete example by providing a file-system tree with files/folders, the config you want to provide, and what the sidebar should look like.
Note that in any case, you can control the sidebar generation logic, including the order, by providing your own generator, or "enhancing" the existing one.
The doc provides an example where the order of the sidebar items is reversed:
https://docusaurus.io/docs/sidebar#customize-the-sidebar-items-generator
Now it's up to you to provide your own ordering logic:
args.docs+sidebarItemsto compute the new order based on your custom frontmatterSomehow, this issue can already be worked around by writing your own sidebarItemsGenerator that include/exclude generated items. We are just looking at providing convenient config so that you don't have to write such logic yourself.
dwmkerr commentedon Feb 24, 2022
Can I suggest we also look at this comment from @slorber:
#3464 (comment)
tl;dr
This would be amazing for me - my book Effective Shell uses a folder per article:
Unless I have missed something, this nesting structure means my sidebars have to look like this:
If instead I could do this:
That would be amazing
9 remaining items
azinit commentedon Sep 24, 2022
Still actual!
lukaszch commentedon Oct 3, 2022
Is the exclude from autogenerated sidebar option already implemented? I tried it, but it doesn't work in the 2.1 version.
I have only a docs-based site, where one of the docs pages is the initial page, which works great.
I only cannot find a way to hide it from the autogenerated sidebar.
slorber commentedon Oct 6, 2022
If this issue is not closed, this means it's not implemented not released
Interesting use-case to consider, thanks for reporting
blessanm86 commentedon Oct 22, 2022
We have docs in multiple repos. So we use git submodules
Maybe I'm doing things wrong
This is our folder structure
I am trying to generate a sidebar structure of
I am just trying to remove the submodules folder from showing up.
My sidebar config looks like this
I was hoping for something like
{ type: 'autogenerated', dirName: '.' , exclude: ['./submodules/**/*.md']}@internal/awesome-libis a docs generated via typedoc plugin.Everything works as expected, just want to filter out the submodules category from the sidebar.
hrumhurum commentedon Aug 27, 2023
In one of the projects I have a page that should not be visible in a sidebar, but the page still should be associated with it. Allowing a sidebar label to be an empty string in frontmatter of the page perfectly communicates the intent:
This is not strictly an exclusion, it just makes the corresponding sidebar item invisible while keeping the page <-> sidebar association active.
A use case: some pages should not be indexable or observable in navigation because they are shared by direct links only. At the same time, those "secret" pages belong to a larger resource such as Knowledge Base, meaning that the corresponding sidebar should remain visible for such pages to allow further navigation.
MattiasBuelens commentedon Apr 3, 2024
You can implement something like this using a custom sidebar items generator:
See sidebarItemsGenerator.ts for the full code, and this
_category_.jsonfile for an example usage. It's not perfect (thepositionhandling is very hacky), but it does the job. 😁voetberg commentedon Mar 25, 2025
Hello! This seems like a rather old issue but I just want to verify - the
excludefeature in autogenerated was never implemented, correct? Is it still planned? I've been chasing around interlinked issues and couldn't see if it had come to a conclusion or not.MattiasBuelens commentedon Mar 26, 2025
@voetberg If you're feeling adventurous, you can modify your custom sidebar items generator to support something like
exclude. See our implementation and an example usage. 😉Blargian commentedon Jul 3, 2025
I'd love to see a way to control ordering of sidebar items directly from the sidebar declaration. For example, I have some autogenerated items for a change log that I want to show in reverse order (e.g version 25.4 first and 22.1 last). It would be cool to be able to do something like this:
I know it's possible to do from the plugin config or from the page metadata but this seems more convenient.
slorber commentedon Jul 3, 2025
@Blargian, the problem with that approach is that it wouldn't play well with our current docs versioning system.
When versioning your docs, we copy and evaluate your dynamic
sidebars.jsfile to a static versioned sidebar JSON fil, which can still contain autogenerated items.It's not possible to encode your item with a custom generator as JSON, so we'd need to entirely rethink the versioning process.
Should we make the versioned sidebars entirely static? We could run your autogenerated items and custom generator logic ahead of time to produce "final" items, but this may produce a worse DX where adding an MDX file to a versioned docs wouldn't appear automatically in the sidebar anymore
Should we emit versioned
sidebars.jsdynamic files? We could do so, but if you use any relative import in it, we must adjust the paths to the new file location, and this possibly opens the door to weird problems on complex site setups.Blargian commentedon Jul 21, 2025
@slorber, thanks for the explanation, that makes sense. What about supporting an
orderproperty in_category_.json? Even something as simple as controlling the order on a per folder basis would be sufficient for what I wanted to achieve. For example:For a folder with structure:
The menu would then display:
slorber commentedon Jul 24, 2025
@Blargian, I don't understand why you would prefix the document with
01_if your goal is to make it appear last. Just prefix it with03_instead.We give you:
sidebar_positionfront matter (that can override the number prefix)parseFrontMatterhook that you can use to eventually generalize and automate the addition ofsidebar_positionfront matterI think that's largely enough to control the position of items.
If you really want to support your weird use case where you reverses the items, you can even implement it yourself with the
parseFrontMatterhook. Here's a pseudo implementation to inspire you:bmaupin commentedon Jan 23, 2026
For excluding items I used the workaround here: https://docusaurus.canny.io/feature-requests/p/hiding-parts-of-docs-in-autogenerated-sidebar
Add custom CSS
Set the class
{ "className": "hiddenFromSidebar" }I also toyed with filtering out items using an overridden sidebar items generator but it didn't seem as clean and I wasn't sure what side effects it might have: