sidebars.js
By default, the sidebars are defined in sidebars.js
in the root folder of this repo.
Under the key config > presents > docs > sidebarPath
is where the path to the sidebars.js
is referred for the docs plugin for Docusaurus.
const config = {
...
presets: [
[
"classic",
{
docs: {
sidebarPath: require.resolve("./sidebars.js"),
...
},
},
],
],
};
Under the key config > themeConfig > navbar > items > sidebarId
, you can specify the key ID that is defined in the sidebars
variable in sidebars.js
. As an example, this can be used if you want a different sidebar for a subset of docs.
Be aware that if you take the shortcut of using the type autogenerated
and dirname
, Docusaurus will recursively take all Markdown files in that folder and make it available on the sidebar.
The only way to prevent this is to explicitly define every page and category that you want in your sidebar. See example from Docusaurus' website.
Using _category_.json
with autogenerated​
It is worth checking out the official docs regarding the sidebar and autogenerated.
The _category_.json
file is usually used in sub-folders where the autogenerate functionality is used. It allows you to tell the autogenerate
feature to respect ordering and customize the category label for the folder that it appears as in the sidebar.
{
"label": "Configuration Files",
"position": 6, // position under in the sidebar under the advanced
"link": {
"type": "generated-index", // by specifying this, clicking on "Configuration Files" in the sidebar will create a generated page with a list of sub-pages that it contains
"description": "Advanced customization of configuration files." // this will appear in the description under the title for the generated page
}
}
If you don't want to generate for when you click on the folder, you can delete the link
key completely.
Or if you want it to point to a custom page instead of an autogenerated one:
{
"label": "Configuration Files",
"position": 6, // position under in the sidebar under the advanced
"link": {
"type": "doc", // type must be doc
"id": "deploy/install-index" //
}
}
Custom slugs​
Under the link
key, you can also specify the slug
.
By default autogenerated pages have the URL as {baseURL}/category/yourDirName
.
{
"label": "Configuration Files",
"position": 6, // position under in the sidebar under the advanced
"link": {
"type": "generated-index", // by specifying this, clicking on "Configuration Files" in the sidebar will create a generated page with a list of sub-pages that it contains
"description": "Advanced customization of configuration files.", // this will appear in the description under the title for the generated page
"slug": "configuration-files" // specify your slug
}
}
You can set the slug to something else if you want to omit the category
subDir.