Configure and use versioning
Docusaurus can manage multiple versions of your documentation. See the Docusaurus versioning documentation for detailed context and instructions on managing versions.
The following instructions are for documentation that uses n versions that can be accessed like so:
Path | Version | URL |
---|---|---|
versioned_docs/version-22.x/hello.md | 22.x | /22.x/hello |
versioned_docs/version-23.x/hello.md | 23.x (latest) | /hello |
docs/hello.md | development | /development/hello |
Please note that unlike Read the Docs (RTD) that versions by tags on the code base, in Docusaurus,
every version in history is kept in the versioned_docs
folder, so the onus is on you to remove
older versions when required
Docusaurus nomenclature is slightly different to what we use. In docusaurus, any version
(i.e. a subfolder in versioned_docs
) is deemed stable; and the next version is therefore called
next
(the next stable version). In Consensys we follow the same for the versioned_docs
but use the
term development
instead, and this can be configured in docusaurus.config.js like so, where
the current
version is given a label
and path
attribute.
...
routeBasePath: "/",
path: "./docs",
includeCurrentVersion: true,
lastVersion: "23.x",
versions: {
//defaults to the ./docs folder
// using 'development' instead of 'next' as path
current: {
label: "development",
path: "development",
},
//the last stable release in the versioned_docs/version-stable
"23.x": {
label: "stable (23.x)",
},
"22.x": {
label: "22.x",
},
},
...
Release a new docs version
1. Create a new version of the documentation:
In the following steps, we'll release the 23.x
version of the documentation (from 22.x
) as an example.
- Syntax
- Example
npm run docusaurus docs:version <VERSION-NUMBER>
npm run docusaurus docs:version 23.x
This command:
- Copies the full
docs/
directory into a newversion-<VERSION-NUMBER>
directory in theversioned_docs
directory. - Creates a new
versioned_sidebars/version-<VERSION-NUMBER>-sidebars.json
file. - Appends the new version number to the
versions.json
file.
Your docs now have two versions:
23.x
athttp://localhost:3000/
for the version 23.x docscurrent
athttp://localhost:3000/next/
for the upcoming, unreleased docs.
2. Update the docusaurus.config.js
file to re-label these paths
In docusaurus.config.js
, under presets
> classic
> docs
:
- Update the
lastVersion
to the new version number. - Under
versions
, update the current version to the new version.
For example, when releasing version 23.x
(from 23.x
), update the following section in the docusaurus.config.js
file by updating the version number:
presets: [
[
"classic",
{
docs: {
sidebarPath: require.resolve("./sidebars.js"),
// Set a base path separate from default /docs
editUrl: "https://github.com/ConsenSys/doc.teku/tree/master/",
routeBasePath: "/",
path: "./docs",
includeCurrentVersion: true,
lastVersion: "23.3.x",
versions: {
//defaults to the ./docs folder
// using 'development' instead of 'next' as path
current: {
label: "development",
path: "development",
},
//the last stable release in the versioned_docs/version-23.x
"23.x": {
label: "stable (23.x)",
},
},
...
],
3. Update the versions.json
file
Please remember to remove any old versions that you are not required
[
"23.x"
]
4. Delete the previous doc versions (if needed)
If you have deleted a version in step 3, also delete the artifacts for that version. For example, if deleting version 22.x
that would mean deleting the following:
- In the
versioned_docs
directory, delete theversion-22.x
folder - In the
versioned_sidebars
directory, delete theversion-22.x-sidebars.json
file.
Create your pull request. You can perform a final check using the preview link generated for your PR.
5. Add a version dropdown (Do this once only when versioning is introduced)
To navigate seamlessly across versions, add a version dropdown by modifying docusaurus.config.js
as follows:
module.exports = {
themeConfig: {
navbar: {
items: [
{
type: "docsVersionDropdown",
},
],
},
},
};
The docs version dropdown appears in your navbar:
Update an existing version
You can edit versioned docs in their respective folder:
versioned_docs/version-23.x/hello.md
updateshttp://localhost:3000/docs/hello
.docs/hello.md
updateshttp://localhost:3000/docs/next/hello
.