Docusaurus
https://docusaurus.community - Knowledge sharing and plugin directory
Doc front matter fields
https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter
Link to another doc
[ESLint](javascript/eslint.md#setup)
[ESLint](/javascript/eslint.md#setup)
[ESLint](/javascript/eslint#setup)
All options produce the same link.
Important: when using the first option you need to add .md
, otherwise you get /dev/javascript/eslint#setup
instead of /javascript/eslint#setup
.
Sidebar
https://docusaurus.io/docs/sidebar
https://docusaurus.io/docs/sidebar/items
const sidebars = {
http: [
'http/http',
'http/https',
'http/cors',
'http/csp',
// There are 2 equivalent ways to make the sidebar label different than the front matter 'title'.
// 1) At the doc front matter set 'sidebar_label'.
// 2) Do this:
{
type: 'doc',
id: 'http/headers',
label: 'Headers',
},
// We can have external links:
{
type: 'link',
label: 'RFC 7231',
href: 'https://httpwg.org/specs/rfc7231.html',
},
],
}
Sidebar category with generated index
The generated index route will be /category/aws
, and the page is accessible by clicking the dropdown.
const sidebars = {
cloud: [
'cloud/cloud',
'cloud/kubernetes',
'cloud/terraform',
{
type: 'category',
label: 'AWS',
link: {
type: 'generated-index',
title: 'AWS',
description: 'Amazon Web Services',
},
collapsed: false,
items: [
'cloud/aws/aws', // Actual link to this page will be '/cloud/aws'
'cloud/aws/iam',
'cloud/aws/ec2',
'cloud/aws/s3',
],
},
'cloud/heroku',
],
}
Sidebar category shorthand syntax
https://docusaurus.io/docs/sidebar/items#category-shorthand
const sidebars = {
docs: {
Docusaurus: ['docs/doc1', 'docs/doc2', 'docs/doc3'],
Features: ['docs/mdx'],
'Docusaurus Tutorial': [
'docs/create-a-page',
'docs/create-a-document',
'docs/markdown-features',
],
},
}
Debug
http://localhost:3000/__docusaurus/debug
https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-debug
Routes
Routes panel: http://localhost:3000/__docusaurus/debug/routes
https://docusaurus.io/docs/advanced/routing
Upgrade
This is the message shown at the terminal when you do npm start
:
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Update available 3.3.2 → 3.4.0
To upgrade Docusaurus packages with the latest version, run the following command:
`npm i @docusaurus/core@latest @docusaurus/preset-classic@latest @docusaurus/module-type-aliases@latest @docusaurus/tsconfig@latest @docusaurus/types@latest`
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Also take a look at the other packages versions:
- https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-preset-classic/package.json
- https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-classic/package.json
OLD (for version 2)
This is the message shown at the terminal when you do npm start
:
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Update available 2.2.0 → 2.4.1 │
│ │
│ To upgrade Docusaurus packages with the latest version, run the following command: │
│ `npm i @docusaurus/core@latest @docusaurus/preset-classic@latest @docusaurus/module-type-aliases@latest` │
│ │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
OLD (with Yarn)
I'm not using Yarn since this commit.
This is the message shown at the terminal when you do yarn start
:
yarn run v1.22.19
$ BROWSER=none docusaurus start
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Update available 2.0.1 → 2.1.0 │
│ │
│ To upgrade Docusaurus packages with the latest version, run the following command: │
│ `yarn upgrade @docusaurus/core@latest @docusaurus/preset-classic@latest @docusaurus/module-type-aliases@latest` │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
You can also do:
yarn upgrade --latest @docusaurus/core @docusaurus/preset-classic @docusaurus/module-type-aliases
Styling
Uses Infima: https://infima.dev
https://docusaurus.io/docs/styling-layout
MDX
A component can be registered globally so that you don't have to import it on every .mdx file. See docs and this tweet.
Code blocks supported languages
https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js
https://docusaurus.io/docs/markdown-features/code-blocks#supported-languages
Server components
https://twitter.com/sebastienlorber/status/1598615824927002624
Releases
- beta 4 - Twitter
- beta 5 - Twitter
- You can now use
<head>
in .md files
- You can now use
- beta 6 - Twitter
- blog/archive route
- beta 7 - Twitter
- beta 10 - Twitter
- Link a sidebar category to an auto-generated index page, eg https://deploy-preview-6076--docusaurus-2.netlify.app/docs/category/guides/
- Link a sidebar category to an existing markdown document
- beta 11, 12, 13 fix issues in 10 deps and bad npm publish
- beta 14 - Twitter
- Simplified footer (if you don't have many links) - https://github.com/facebook/docusaurus/issues/6101
- beta 15 - Twitter
- Option to auto-collapse sidebar categories as you click
- beta 16 - Twitter
- Swizzling - https://docusaurus.io/docs/swizzling
- Breadcrumbs in docs (disabled in config.js with presets docs.breadcrumbs)
- Add arbitrary html elements to the docs sidebar like images, separators etc.
- beta 17 - Twitter
- beta 18 - Twitter
- beta 19 - Twitter
- beta 20 - Twitter
- Small release with fixes for beta 19
- beta 21 - Twitter
- beta 22 - Twitter
- 2.0.0-rc.1 - Twitter
- 2.0 - Announcement - Twitter - HN
- 2.1 - Announcement - Twitter
- Allows to override hardcoded
<meta>
- Simple use
<DocCardList/>
, which can now be used in any document.DocCardList
"will display all the sidebar items of the parent category of the current document" source
- Allows to override hardcoded
- 2.2 - Announcement - Twitter
- 2.3 - Announcement - Twitter
- Nested alerts (admonitions)
- 2.4 - Announcement - Twitter
- Sidebar item of type category or link can have description
- Use query string
?docusaurus-theme=dark
or?docusaurus-theme=light
to force light or dark mode
- 3.0 - Announcement - Twitter
- Upgrade guide. Also see Preparing your site for Docusaurus v3
- MDX 3
- Support for ES Modules and TypeScript config files (
docusaurus.config.ts
andsidebars.ts
) - Admonitions:
- Fix and re-introduce the
:::warning
admonition (is now yellow instead of red) - Deprecate
:::caution
. Refactor:::caution
(yellow) to either:::warning
(yellow) or:::danger
(red)
- Fix and re-introduce the
- New
unlisted: true
front matter option, in addition to the already existingdraft: true
- Build your static site in dev mode with
docusaurus build --dev
. Particularly helpful for troubleshooting React problems - Code blocks syntax highlighting with Prism 2 only includes a few languages. You need to add the other ones manually in
docusaurus.config.js
- 3.1 - Announcement - Twitter
parseFrontMatter
hook, which allows to disable the 'Previous' and 'Next' links- Built-in broken anchors detector, with new option
onBrokenAnchors
- 3.2 - Announcement - Twitter
- 3.3 - Announcement - Twitter
- 3.4 - Announcement - Twitter
- Tags files (
blog/tags.yml
anddocs/tags.yml
): list of pre-defined tags, to reuse them and validate them - Hash router: generates a single page app
index.html
file that allows easy distribution and offline browsing locally without a web server (using thefile://
protocol)
- Tags files (
- 3.5 - Announcement - Twitter
- Improvements to the blog, eg authors pages with social icons
- 3.6 - Announcement - Twitter
- Faster builds with Rust-based tools (opt-in)