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.
Versioning is most useful for projects with high traffic and frequent changes between releases. If your docs rarely change, avoid versioning to keep things simple.
Overviewโ
A typical versioned documentation structure looks like this:
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 # list of available versions
โโโ versioned_docs
โ โโโ version-1.1.0
โ โ โโโ hello.md # https://mysite.com/docs/hello
โ โโโ version-1.0.0
โ โโโ hello.md # https://mysite.com/docs/1.0.0/hello
โโโ versioned_sidebars
โ โโโ version-1.1.0-sidebars.json
โ โโโ version-1.0.0-sidebars.json
โโโ docusaurus.config.js
| File 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 |
Terminologyโ
- Current version โ The content stored in the
./docsfolder. - Latest version โ The version served by default on
/docs. This is defined by navigation, not by file location.
These may or may not be the same.
Tutorialsโ
Tagging a new versionโ
- Prepare the
./docsfolder for release. - Run the versioning command:
npm run docusaurus docs:version 1.1.0
This will:
- Copy the
docs/folder intoversioned_docs/version-1.1.0/. - Create a versioned sidebar file
versioned_sidebars/version-1.1.0-sidebars.json. - Append
1.1.0toversions.json.
Creating new docsโ
- Current version
- Older version
docs/new.md
# Edit sidebar.js for the current version
versioned_docs/version-1.0.0/new.md
# Edit versioned_sidebars/version-1.0.0-sidebars.json
Updating an existing versionโ
Simply edit the files inside the appropriate versioned_docs directory
and commit the changesโthey will apply only to that version.
Deleting a versionโ
- Remove it from
versions.json. - Delete the corresponding
versioned_docsandversioned_sidebarsdirectories.
Configuring behaviorโ
Key plugin options:
disableVersioningโ Force-disable versioning.includeCurrentVersionโ Decide if the./docsfolder should be published.lastVersionโ Control which version/docspoints to.onlyIncludeVersionsโ Deploy only a subset of versions.versionsโ Customize labels, paths, banners, badges, etc.
Example: treating current as a released version:
export default {
presets: [
'@docusaurus/preset-classic',
{
docs: {
lastVersion: 'current',
versions: {
current: {
label: '1.0.0',
path: '1.0.0',
},
},
},
},
],
};
Navbar Itemsโ
Docusaurus provides built-in navbar types:
docโ Link to a doc.docSidebarโ Link to the first item in a sidebar.docsVersionโ Link to the main doc of the current version.docsVersionDropdownโ Dropdown of all versions.
These automatically resolve the best version to display.
Recommended Practicesโ
- Version only when necessary โ avoid cutting versions for small patch releases.
- Keep versions manageable โ aim for fewer than ~10 active versions.
- Use absolute imports with
@sitealias to avoid broken paths across versions. - Link docs by file paths (
.md), letting Docusaurus rewrite URLs correctly. - Decide asset strategy โ store images/files either in versioned folders (for frozen snapshots) or in
/staticfor shared use.
By following these guidelines, you can maintain a clean and scalable documentation workflow while supporting multiple versions of your project.