Versioning
You can use the versioning CLI to create a new documentation version based on the latest content in the docs
directory. That specific set of documentation will then be preserved and accessible even as the documentation in the docs
directory continues to evolve.
Think about it before starting to version your documentation - it can become difficult for contributors to help improve it!
Most of the time, you don't need versioning as it will just increase your build time, and introduce complexity to your codebase. Versioning is best suited for websites with high-traffic and rapid changes to documentation between versions. If your documentation rarely changes, don't add versioning to your documentation.
To better understand how versioning works and see if it suits your needs, you can read on below.
Overviewβ
A typical versioned doc site looks like below:
website
βββ sidebars.json # sidebar for the current docs version
βββ docs # docs directory for the current docs version
β βββ foo
β β βββ bar.md # https://mysite.com/docs/next/foo/bar
β βββ hello.md # https://mysite.com/docs/next/hello
βββ versions.json # file to indicate what versions are available
βββ versioned_docs
β βββ version-1.1.0
β β βββ foo
β β β βββ bar.md # https://mysite.com/docs/foo/bar
β β βββ hello.md
β βββ version-1.0.0
β βββ foo
β β βββ bar.md # https://mysite.com/docs/1.0.0/foo/bar
β βββ hello.md
βββ versioned_sidebars
β βββ version-1.1.0-sidebars.json
β βββ version-1.0.0-sidebars.json
βββ docusaurus.config.js
βββ package.json
The versions.json
file is a list of version names, ordered from newest to oldest.
The table below explains how a versioned file maps to its version and the generated URL.
Path | Version | URL |
---|---|---|
versioned_docs/version-1.0.0/hello.md | 1.0.0 | /docs/1.0.0/hello |
versioned_docs/version-1.1.0/hello.md | 1.1.0 (latest) | /docs/hello |
docs/hello.md | current | /docs/next/hello |
The files in the docs
directory belong to the current
docs version.
By default, the current
docs version is labeled as Next
and hosted under /docs/next/*
, but it is entirely configurable to fit your project's release lifecycle.
Terminologyβ
Note the terminology we use here.
- Current version
- The version placed in the
./docs
folder. - Latest version / last version
- The version served by default for docs navbar items. Usually has path
/docs
.
Current version is defined by the file system location, while latest version is defined by the the navigation behavior. They may or may not be the same version! (And the default configuration, as shown in the table above, would treat them as different: current version at /docs/next
and latest at /docs
.)
Tutorialsβ
Tagging a new versionβ
- First, make sure the current docs version (the
./docs
directory) is ready to be frozen. - Enter a new version number.
- npm
- Yarn
- pnpm
npm run docusaurus docs:version 1.1.0
yarn docusaurus docs:version 1.1.0
pnpm run docusaurus docs:version 1.1.0
When tagging a new version, the document versioning mechanism will:
- Copy the full
docs/
folder contents into a newversioned_docs/version-[versionName]/
folder. - Create a versioned sidebars file based from your current sidebar configuration (if it exists) - saved as
versioned_sidebars/version-[versionName]-sidebars.json
. - Append the new version number to
versions.json
.
Creating new docsβ
- Place the new file into the corresponding version folder.
- Include the reference to the new file in the corresponding sidebar file according to the version number.
- Current version structure
- Older version structure
# The new file.
docs/new.md
# Edit the corresponding sidebar file.
sidebars.js
# The new file.
versioned_docs/version-1.0.0/new.md
# Edit the corresponding sidebar file.
versioned_sidebars/version-1.0.0-sidebars.json
Versioned sidebar files are, like standard sidebar files, relative to the content root for the given version β so for the example above, your versioned sidebar file may look like:
{
"sidebar": [
{
"type": "autogenerated",
"dirName": "."
}
]
}
or for a manual sidebar:
{
"sidebar": [
{
"type": "doc",
"id": "new",
"label": "New"
}
]
}
Updating an existing versionβ
You can update multiple docs versions at the same time because each directory in versioned_docs/
represents specific routes when published.
- Edit any file.
- Commit and push changes.
- It will be published to the version.
Example: When you change any file in versioned_docs/version-2.6/
, it will only affect the docs for version 2.6
.
Deleting an existing versionβ
You can delete/remove versions as well.
- Remove the version from
versions.json
.
Example:
[
"2.0.0",
"1.9.0",
- "1.8.0"
]
- Delete the versioned docs directory. Example:
versioned_docs/version-1.8.0
. - Delete the versioned sidebars file. Example:
versioned_sidebars/version-1.8.0-sidebars.json
.