2020-10-25 16:14:02 +01:00
|
|
|
|
---
|
|
|
|
|
template: overrides/main.html
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# Setting up versioning
|
|
|
|
|
|
|
|
|
|
Material for MkDocs makes it easy to deploy multiple versions of your project
|
|
|
|
|
documentation by integrating with external utilities that add those capabilities
|
2021-10-10 19:22:13 +02:00
|
|
|
|
to MkDocs, i.e. [mike]. When deploying a new version, older versions of your
|
2020-10-25 16:14:02 +01:00
|
|
|
|
documentation remain untouched.
|
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
[mike]: https://github.com/jimporter/mike
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
|
|
### Versioning
|
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
[:octicons-tag-24: 7.0.0][version support] ·
|
|
|
|
|
[:octicons-package-24: Utility][mike]
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
[mike] makes it easy to deploy multiple versions of your project documentation.
|
|
|
|
|
It integrates natively with Material for MkDocs and can be enabled via
|
|
|
|
|
`mkdocs.yml`:
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
extra:
|
|
|
|
|
version:
|
2021-02-22 21:01:04 +01:00
|
|
|
|
provider: mike
|
2020-10-25 16:14:02 +01:00
|
|
|
|
```
|
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
This renders a version selector in the header:
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
2021-10-04 23:36:31 +02:00
|
|
|
|
<figure markdown>
|
2020-12-22 14:20:20 +01:00
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
[![Version selector preview]][Version selector preview]
|
2020-12-22 14:20:20 +01:00
|
|
|
|
|
2021-10-04 23:36:31 +02:00
|
|
|
|
<figcaption markdown>
|
2020-12-22 14:20:20 +01:00
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
Check out the versioning example to see it in action –
|
|
|
|
|
[squidfunk.github.io/mkdocs-material-example-versioning][version example]
|
2020-12-22 14:20:20 +01:00
|
|
|
|
|
2020-12-21 17:38:58 +01:00
|
|
|
|
</figcaption>
|
|
|
|
|
</figure>
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
!!! quote "[Why use mike?]"
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
|
|
|
|
mike is built around the idea that once you've generated your docs for a
|
|
|
|
|
particular version, you should never need to touch that version again. This
|
|
|
|
|
means you never have to worry about breaking changes in MkDocs, since your
|
|
|
|
|
old docs (built with an old version of MkDocs) are already generated and
|
|
|
|
|
sitting in your `gh-pages` branch.
|
|
|
|
|
|
|
|
|
|
While mike is flexible, it's optimized around putting your docs in a
|
|
|
|
|
`<major>.<minor>` directory, with optional aliases (e.g. `latest` or `dev`)
|
|
|
|
|
to particularly notable versions. This makes it easy to make permalinks to
|
|
|
|
|
whatever version of the documentation you want to direct people to.
|
|
|
|
|
|
2021-10-10 19:22:13 +02:00
|
|
|
|
[version support]: https://github.com/squidfunk/mkdocs-material/releases/tag/5.2.0
|
|
|
|
|
[Version selector preview]: ../assets/screenshots/versioning.png
|
|
|
|
|
[version example]: https://squidfunk.github.io/mkdocs-material-example-versioning/
|
|
|
|
|
[Why use mike?]: https://github.com/jimporter/mike#why-use-mike
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
2021-03-28 19:46:59 +02:00
|
|
|
|
### Version warning
|
|
|
|
|
|
2021-11-28 16:58:52 +01:00
|
|
|
|
[:octicons-tag-24: 8.0.0][Version warning support] ·
|
2021-10-10 21:04:22 +02:00
|
|
|
|
:octicons-file-symlink-file-24: Customization
|
2021-03-28 19:46:59 +02:00
|
|
|
|
|
|
|
|
|
If you're using versioning, you might want to display a warning when the user
|
2021-10-10 21:04:22 +02:00
|
|
|
|
visits any other version than the latest version. Using [theme extension],
|
|
|
|
|
you can [override the `outdated` block][overriding blocks]:
|
2021-03-28 19:46:59 +02:00
|
|
|
|
|
2021-07-18 17:57:45 +02:00
|
|
|
|
``` html
|
2021-09-12 10:15:21 +02:00
|
|
|
|
{% extends "base.html" %}
|
|
|
|
|
|
2021-03-28 19:46:59 +02:00
|
|
|
|
{% block outdated %}
|
|
|
|
|
You're not viewing the latest version.
|
2021-12-11 14:30:07 +01:00
|
|
|
|
<a href="{{ '../' ~ base_url }}"> <!-- (1)! -->
|
2021-05-30 12:39:20 +02:00
|
|
|
|
<strong>Click here to go to latest.</strong>
|
2021-03-28 19:46:59 +02:00
|
|
|
|
</a>
|
|
|
|
|
{% endblock %}
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-10 12:19:14 +02:00
|
|
|
|
1. Given this value for the `href` attribute, the link will always redirect to
|
|
|
|
|
the root of your site, which will then redirect to the latest version. This
|
|
|
|
|
ensures that older versions of your site do not depend on a specific alias,
|
|
|
|
|
e.g. `latest`, to allow for changing the alias later on without breaking
|
|
|
|
|
earlier versions.
|
2021-06-17 08:51:16 +02:00
|
|
|
|
|
2021-03-28 19:46:59 +02:00
|
|
|
|
This will render a version warning above the header:
|
|
|
|
|
|
2021-10-10 21:04:22 +02:00
|
|
|
|
[![Version warning preview]][Version warning preview]
|
2021-03-28 19:46:59 +02:00
|
|
|
|
|
2021-10-10 21:04:22 +02:00
|
|
|
|
The default version is identified by the `latest` alias. If you wish to set
|
|
|
|
|
another alias as the latest version, e.g. `stable`, add the following lines
|
|
|
|
|
to `mkdocs.yml`:
|
2021-03-28 19:46:59 +02:00
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
extra:
|
|
|
|
|
version:
|
|
|
|
|
default: stable
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-10 21:04:22 +02:00
|
|
|
|
Make sure that this matches the [default version].
|
2021-03-28 19:46:59 +02:00
|
|
|
|
|
2021-11-28 16:58:52 +01:00
|
|
|
|
[Version warning support]: https://github.com/squidfunk/mkdocs-material/releases/tag/8.0.0
|
2021-10-10 21:04:22 +02:00
|
|
|
|
[theme extension]: ../customization.md#extending-the-theme
|
|
|
|
|
[overriding blocks]: ../customization.md#overriding-blocks
|
|
|
|
|
[Version warning preview]: ../assets/screenshots/version-warning.png
|
|
|
|
|
[default version]: #setting-a-default-version
|
2021-03-28 19:46:59 +02:00
|
|
|
|
|
2020-10-25 16:14:02 +01:00
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
|
|
While this section outlines the basic workflow for publishing new versions,
|
2021-10-10 21:04:22 +02:00
|
|
|
|
it's best to check out [mike's documentation][mike] to make yourself familar
|
|
|
|
|
with its mechanics.
|
2020-10-25 16:14:02 +01:00
|
|
|
|
|
|
|
|
|
### Publishing a new version
|
|
|
|
|
|
2020-10-25 17:03:19 +01:00
|
|
|
|
If you want to publish a new version of your project documentation, choose a
|
2020-10-25 16:14:02 +01:00
|
|
|
|
version identifier and update the alias set as the default version with:
|
|
|
|
|
|
|
|
|
|
```
|
2020-10-25 17:03:19 +01:00
|
|
|
|
mike deploy --push --update-aliases 0.1 latest
|
2020-10-25 16:14:02 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Note that every version will be deployed as a subdirectory of your `site_url`,
|
|
|
|
|
e.g.:
|
|
|
|
|
|
2021-04-11 18:09:04 +02:00
|
|
|
|
- _docs.example.com/0.1/_
|
|
|
|
|
- _docs.example.com/0.2/_
|
2020-10-25 16:14:02 +01:00
|
|
|
|
- ...
|
2020-10-25 17:03:19 +01:00
|
|
|
|
|
|
|
|
|
### Setting a default version
|
|
|
|
|
|
2021-10-10 21:04:22 +02:00
|
|
|
|
When starting with [mike], a good idea is to set an alias as a default version,
|
|
|
|
|
e.g. `latest`, and when publishing a new version, always update the alias to
|
|
|
|
|
point to the latest version:
|
2020-10-25 17:03:19 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
mike set-default --push latest
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-10 21:04:22 +02:00
|
|
|
|
When publishing a new version, [mike] will create a redirect in the root of
|
2020-10-25 17:03:19 +01:00
|
|
|
|
your project documentation to the version associated with the alias:
|
|
|
|
|
|
|
|
|
|
_docs.example.com_ :octicons-arrow-right-24: _docs.example.com/0.1_
|