Multi version
Rspress's default theme supports multi-version document management. Next, we will introduce how to access multi-version documents.
multiVersion
config
Configure the version list and default version through multiVersion
, for example:
import { defineConfig } from '@rspress/core';
export default defineConfig({
multiVersion: {
default: 'v1',
versions: ['v1', 'v2'],
},
});
Here, default
is the default version, and versions
is the version list.
Adding multi-version documents
According to the version list you configured, add multi-version documents under the docs
directory, for example:
docs
βββ v1
β βββ README.md
β βββ guide
β βββ README.md
βββ v2
βββ README.md
βββ guide
βββ README.md
In Rspress's conventional routing, for the default version, the version path prefix will be automatically omitted. For example, v1/README.md
will be rendered as the /README
route, while v2/README.md
will be rendered as the /v2/README
route.
For links in the document, you do not need to manually add the version prefix. Rspress will automatically add the corresponding version prefix according to the version of the current document. For example, the link /guide/README
in v2/README.md
will be rendered as /v2/guide/README
.
Get the current version in components
In components, you can get the current version through useVersion
, for example:
import { useVersion } from '@rspress/core/runtime';
export default () => {
const version = useVersion();
return <div>Current version: {version}</div>;
};
Limit search to current version only
You can configure search.versioned
to only search through the current version's documents.
import { defineConfig } from '@rspress/core';
export default defineConfig({
multiVersion: {
default: 'v1',
versions: ['v1', 'v2'],
},
search: {
versioned: true,
},
});