Docs Introduction
The docs feature provides users with a way to organize Markdown files in a hierarchical format.
#
Document IDEvery 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 front matter. For example, if guide/hello.md
's content is defined as below, its final id
is guide/part1
.
If you want more control over the last part of the document URL, it is possible to add a slug
(defaults to the id
).
note
It is possible to use:
- absolute slugs:
slug: /mySlug
,slug: /
... - relative slugs:
slug: mySlug
,slug: ./../mySlug
...
#
Home page docsIf you want a document to be available at the root, and have a path like https://v2.docusaurus.io/docs/
, you can use the slug frontmatter:
#
SidebarTo 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
.
#
Hideable sidebarUsing the enabled themeConfig.hideableSidebar
option, you can make the entire sidebar hided, allowing you to better focus your users on the content. This is especially useful when content consumption on medium screens (e.g. on tablets).
#
Sidebar objectA 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.
Keep in mind that EcmaScript does not guarantee Object.keys({a,b}) === ['a','b']
(yet, this is generally true). 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 shorthand syntax.
You can also have multiple sidebars for different Markdown files by adding more top-level keys to the exported object.
Example:
#
Sidebar itemAs the name implies, SidebarItem
is an item defined in a Sidebar. There are a few types we support:
#
DocSidebar 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
.
#
LinkSidebar item type that links to a non-document page. Example:
#
RefSidebar item type that links to doc without bounding it to the sidebar. Example:
#
CategoryThis 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:
Note: it's possible to use the shorthand syntax to create nested categories:
#
Collapsible categoriesFor 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
:
#
Expanded categories by defaultFor docs that have collapsible categories, you may want more fine-grain control over certain categories. If you want specific categories to be always expanded, you can set collapsed
to false
:
#
Docs-only modeIf you only want the documentation feature, you can run your Docusaurus 2 site without a landing page and display your documentation page as the index page instead.
To enable docs-only mode, set the docs plugin routeBasePath: '/'
, and use the frontmatter slug: /
on the document that should be the index page (more infos).
caution
You should delete the existing homepage at ./src/pages/index.js
, or else there will be two files mapping to the same route!
tip
There's also a "blog-only mode" for those who only want to use the blog feature of Docusaurus 2. You can use the same method detailed above. Follow the setup instructions on Blog-only mode.