Skip to content
套用主题

欢迎来到我的网站

Docs Introduction

Your site’s documentation is organized by four levels, from lowest to highest:

  1. Individual(单独) pages.
  2. Sidebars.
  3. Versions.
  4. Plugin instances.

The guide will introduce them in that order:

  • starting from how individual pages can be configured
  • how to create a sidebar or multiple ones
  • how to create and manage versions
  • how to use multiple docs plugin instances.

Docs-only mode

A freshly initialized Docusaurus site has the following structure:

example.com/ -> generated from `src/pages/index.js`
example.com/docs/intro -> generated from `docs/intro.md`
example.com/docs/tutorial-basics/... -> generated from `docs/tutorial-basics/...`
...
example.com/blog/2021/08/26/welcome -> generated from `blog/2021-08-26-welcome/index.md`
example.com/blog/2021/08/01/mdx-blog-post -> generated from `blog/2021-08-01-mdx-blog-post.mdx`
...

All docs will be served under the subroute docs/. But what if your site only has docs, or you want to prioritize your docs by putting them at the root?

Assume that you have the following in your configuration:

docusaurus.config.js
export default {
// ...
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
/* docs plugin options */
},
blog: {
/* blog plugin options */
},
// ...
},
],
],
};

To enter docs-only mode, change it to like this:

docusaurus.config.js
export default {
// ...
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
routeBasePath: '/', // Serve the docs at the site's root
/* other docs plugin options */
},
blog: false, // Optional: disable the blog plugin
// ...
},
],
],
};

instead of serving the docs through https://example.com/docs/some-doc, now at the site root: https://example.com/some-doc

重新定位主页

重定向主页方法,例如:把docs/intro.md作为首页(即打开https://example.com/则显示intro.md)

  1. 编辑docs/intro.md

    ---
    slug: /
    // 其他不变
    ---
    // 其他不变
  2. you should delete the existing homepage at ./src/pages/index.js , 否则会造成Duplicate Routes(即点击导航内的首页docs都显示intro.md)

  3. Now, the site’s structure will be like the following:

    example.com/ -> generated from `docs/intro.md`
    example.com/tutorial-basics/... -> generated from `docs/tutorial-basics/...`
    ...

同样也可以关闭Docs,开启Blog-only mode