Multi version docs support #110
sanyuan0704
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Multi language overview
Currently, rspress supports multi language docs.That is to say:
Rspress will automatically generate a language switcher in the navbar.
Rspress will automatically add the language prefix to the link in docs, such as
/en/
or/zh/
.But in default language, the prefix will not be added.Multi version usage
1. File structure
But sometimes we also need multi version docs, such as the following file structure:
Also, the multi version may be combined with multi language, such as the following file structure:
2. Config
In the
rspress.config.ts
file, you can configure the multi version docs:The
default
parameter is the default version, and theversions
parameter is the version list.Then the user has integrated the multi version feature. The framework will do the following:
Automatically add the language prefix to the link in docs, such as
/v1/
or/v2/
.For default version, the version prefix in path will not be added.
Provide
useVersion
hook to get the current version in custom components in docs.Implement
The implement will include the following parts:
RouteService, which is responsible for generating the convential routes and the routes for multi version.
Links Rewrite. For the links in md(x) file, we need to rewrite them to the convential routes or the routes for multi version, for example,
/guide/getting-started.md
will be rewrited to/v1/guide/getting-started.md
.The rewrite process is implement byusePathUtils
hook in runtime.Maybe you could ask the question: why not rewrite the links in compile time? Taking account of that the mdx compiler includes two versions: in JS and in Rust.So if we implement the link rewrite in runtime, we will have no need to adapt the two versions of mdx compiler.
The implement pr is here.
In the Future
To support multi version docs, we can do more things in the future:
versions
config:If you have any ideas, please feel free to discuss or open a pr.
Beta Was this translation helpful? Give feedback.
All reactions