Sidebar
To generate a sidebar to your Docusaurus site, you need to define a file that exports a sidebar object and pass that into the @docusaurus/plugin-docs
plugin directly or via @docusaurus/preset-classic
.
Sidebar object
A sidebar object is defined like this.
Below is an example of a sidebar object. The key docs
is the id of the sidebar (can be renamed to something else) and Getting Started
is a category within the sidebar. greeting
and doc1
are both sidebar item.
If you don't want to rely on iteration order of JavaScript object keys for the category name, the following sidebar object is also equivalent of the above.
You can also have multiple sidebars for different Markdown files by adding more top-level keys to the exported object.
Example:
Document ID
Every document has a unique id
. By default, a document id
is the name of the document (without the extension) relative to the root docs directory.
For example, greeting.md
id is greeting
and guide/hello.md
id is guide/hello
.
However, the last part of the id
can be defined by user in the frontmatter. For example, if guide/hello.md
content is defined as below, it's final id
is guide/part1
.
Sidebar item
As the name implies, SidebarItem
is an item defined in a Sidebar. There are a few types we support:
Doc
Sidebar item type that links to a doc page. Example:
Using just the Document ID is perfectly valid as well, the following is equivalent to the above:
Note that using this type will bind the linked doc to current sidebar, this means that if you access doc1
page, the sidebar displayed will be the sidebar this item is on. For below case, doc1
is bounded to firstSidebar
.
Link
Sidebar item type that links to a non-document page. Example:
Ref
Sidebar item type that links to doc without bounding it to the sidebar. Example:
Category
This is used to add hierarchies to the sidebar:
As an example, here's how we created the subcategory for "Docs" under "Guides" in this site:
Collapsible categories
For sites with a sizable amount of content, we support the option to expand/collapse a category to toggle the display of its contents. Categories are collapsible by default. If you want them to be always expanded, set themeConfig.sidebarCollapsible
to false
: