Versioning
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.