Multi version docs support #110
Closed
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Multi language overview
Currently, rspress supports multi language docs.That is to say:
doc ├── en │ ├── index.md │ └── guide │ ├── getting-started.md │ └── introduction.md └── zh ├── index.md └── guide ├── getting-started.md └── introduction.mdRspress 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:
doc ├── v1 │ ├── index.md │ └── guide │ ├── getting-started.md │ └── introduction.md └── v2 ├── index.md └── guide ├── getting-started.md └── introduction.mdAlso, the multi version may be combined with multi language, such as the following file structure:
doc ├── v1 │ ├── en │ │ ├── index.md │ │ └── guide │ │ ├── getting-started.md │ │ └── introduction.md │ └── zh │ ├── index.md │ └── guide │ ├── getting-started.md │ └── introduction.md └── v2 ├── en │ ├── index.md │ └── guide │ ├── getting-started.md │ └── introduction.md └── zh ├── index.md └── guide ├── getting-started.md └── introduction.md2. Config
In the
rspress.config.tsfile, you can configure the multi version docs:The
defaultparameter is the default version, and theversionsparameter 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
useVersionhook 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.mdwill be rewrited to/v1/guide/getting-started.md.The rewrite process is implement byusePathUtilshook 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:
versionsconfig:If you have any ideas, please feel free to discuss or open a pr.
Beta Was this translation helpful? Give feedback.
All reactions