You can use the version script to cut 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 changes moving forward.
Consider it really well before starting to version your documentation.
Most of the times, you don't need versioning and it will just increase your build time and introduces complexity to your codebase. Versioning is best suited for website with high-traffic and rapid changes in documentation between version. If your documentation rarely changes, don't add versions to the website.
To better understand how versioning works and see if it suits your needs, you can read on below.
The table below explains how a versioned file maps to its version and the generated URL.
Tagging a new version
- First, make sure your content in the
docsdirectory is ready to be frozen as a version. A version always should be based from master.
- Enter a new version number.
When tagging a new version, the document versioning mechanism will:
- Copy the full
docs/folder contents into a new
- Create a versioned sidebars file based from your current sidebar configuration (if it exists). Saved it as
- Append the new version number into
Creating new files
- Place the new file into the corresponding version folder.
- Include the reference for the new file into the corresponding sidebar file, according to version number.
- Remember to include the
- Files will be linked to correct corresponding version.
- Relative paths work as well.
Each directory in
versioned_docs/ will represent a documentation version.
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
Deleting an existing version
You can delete/remove versions as well.
- Remove the version from
- Delete the versioned docs directory. Example:
- Delete the versioned sidebars file. Example:
Version your documentation only when needed
For example, you are building a documentation for your npm package
foo and you are currently in version 1.0.0. You then release a patch version for a minor bug fix and it's now 1.0.1.
Should you cut a new documentation version 1.0.1? You probably shouldn't. 1.0.1 and 1.0.0 docs shouldn't differ according to semver because there are no new features!. Cutting a new version for it will only just create unnecessary duplicated files.
Keep the number of versions small
As a good rule of thumb, try to keep the number of your versions below 10. It is very likely that you will have a lot of obsolete versioned documentation that nobody even reads anymore. For example, Jest is currently in version
24.9, and only maintains several latest documentation version with the lowest being
22.X. Keep it small 😊
Use absolute import within the docs
Don't use relative paths import within the docs. Because when we cut a version the paths no longer work (the nesting level is different, among other reasons). You can utilize the
@site alias provided by docusaurus, that points to the
website directory. Example: