2020-10-25 18:14:02 +03: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
|
|
|
|
to MkDocs, i.e. [mike][1]. When deploying a new version, older versions of your
|
|
|
|
documentation remain untouched.
|
|
|
|
|
|
|
|
[1]: https://github.com/jimporter/mike
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
### Versioning
|
|
|
|
|
|
|
|
[:octicons-file-code-24: Source][2] ·
|
2021-02-27 11:14:15 +03:00
|
|
|
[:octicons-package-24: Utility][1]
|
2020-10-25 18:14:02 +03:00
|
|
|
|
|
|
|
[mike][1] 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`:
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
extra:
|
|
|
|
version:
|
2021-02-22 23:01:04 +03:00
|
|
|
provider: mike
|
2020-10-25 18:14:02 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
This will render a version selector in the header next to the title of your
|
|
|
|
project:
|
|
|
|
|
2021-10-05 00:36:31 +03:00
|
|
|
<figure markdown>
|
2020-12-22 16:20:20 +03:00
|
|
|
|
|
|
|
[![Version selection][3]][3]
|
|
|
|
|
2021-10-05 00:36:31 +03:00
|
|
|
<figcaption markdown>
|
2020-12-22 16:20:20 +03:00
|
|
|
|
|
|
|
A demo is worth a thousand words — check it out at
|
|
|
|
[squidfunk.github.io/mkdocs-material-example-versioning][4]
|
|
|
|
|
2020-12-21 19:38:58 +03:00
|
|
|
</figcaption>
|
|
|
|
</figure>
|
2020-10-25 18:14:02 +03:00
|
|
|
|
|
|
|
!!! quote "[Why use mike?][5]"
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2020-12-21 19:38:58 +03:00
|
|
|
_Note that you don't need to run_ `mike install-extras` _as noted in the
|
2020-10-25 19:03:19 +03:00
|
|
|
[official documentation][6], as [mike][1] is now natively integrated with
|
|
|
|
Material for MkDocs._
|
|
|
|
|
2021-02-22 23:01:04 +03:00
|
|
|
[2]: https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/header.html
|
2020-10-25 18:14:02 +03:00
|
|
|
[3]: ../assets/screenshots/versioning.png
|
2020-10-25 19:03:19 +03:00
|
|
|
[4]: https://squidfunk.github.io/mkdocs-material-example-versioning/
|
2020-10-25 18:14:02 +03:00
|
|
|
[5]: https://github.com/jimporter/mike#why-use-mike
|
2020-10-25 19:03:19 +03:00
|
|
|
[6]: https://github.com/jimporter/mike#usage
|
2020-10-25 18:14:02 +03:00
|
|
|
|
2021-03-28 20:46:59 +03:00
|
|
|
### Version warning
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
[:octicons-heart-fill-24:{ .mdx-heart } Insiders][Insiders]{ .mdx-insiders } ·
|
|
|
|
:octicons-file-symlink-file-24: Customization ·
|
2021-10-10 18:39:53 +03:00
|
|
|
[:octicons-tag-24: insiders-2.5.0][Insiders]
|
2021-03-28 20:46:59 +03:00
|
|
|
|
|
|
|
If you're using versioning, you might want to display a warning when the user
|
|
|
|
visits any other version than the latest version. Using [theme extension][8],
|
|
|
|
you can [define the `outdated` block][9]:
|
|
|
|
|
2021-07-18 18:57:45 +03:00
|
|
|
``` html
|
2021-09-12 11:15:21 +03:00
|
|
|
{% extends "base.html" %}
|
|
|
|
|
2021-03-28 20:46:59 +03:00
|
|
|
{% block outdated %}
|
|
|
|
You're not viewing the latest version.
|
2021-06-17 09:51:16 +03:00
|
|
|
<a href="{{ '../' ~ base_url }}"> <!-- (1) -->
|
2021-05-30 13:39:20 +03:00
|
|
|
<strong>Click here to go to latest.</strong>
|
2021-03-28 20:46:59 +03:00
|
|
|
</a>
|
|
|
|
{% endblock %}
|
|
|
|
```
|
|
|
|
|
2021-10-10 13:19:14 +03: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 09:51:16 +03:00
|
|
|
|
2021-03-28 20:46:59 +03:00
|
|
|
This will render a version warning above the header:
|
|
|
|
|
|
|
|
[![Version warning][10]][10]
|
|
|
|
|
|
|
|
By default, 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 to `mkdocs.yml`:
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
extra:
|
|
|
|
version:
|
|
|
|
default: stable
|
|
|
|
```
|
|
|
|
|
|
|
|
Make sure that this matches the [default version][11].
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
[Insiders]: ../insiders/index.md
|
2021-03-28 20:46:59 +03:00
|
|
|
[7]: ../insiders/index.md
|
|
|
|
[8]: ../customization.md#extending-the-theme
|
2021-05-01 21:26:54 +03:00
|
|
|
[9]: ../customization.md#overriding-blocks-recommended
|
2021-03-28 20:46:59 +03:00
|
|
|
[10]: ../assets/screenshots/version-warning.png
|
|
|
|
[11]: #setting-a-default-version
|
|
|
|
|
2021-04-11 19:09:04 +03:00
|
|
|
### Stay on page
|
|
|
|
|
2021-10-03 21:28:52 +03:00
|
|
|
[:octicons-heart-fill-24:{ .mdx-heart } Insiders][Insiders]{ .mdx-insiders } ·
|
2021-10-10 18:39:53 +03:00
|
|
|
[:octicons-tag-24: insiders-2.6.0][Insiders]
|
2021-04-11 19:09:04 +03:00
|
|
|
|
|
|
|
Insiders improves the user experience when switching between versions: if
|
|
|
|
version A and B contain a page with the same path name, the user will stay on
|
|
|
|
the current page:
|
|
|
|
|
|
|
|
=== "New behavior"
|
|
|
|
|
|
|
|
```
|
|
|
|
docs.example.com/0.1/ -> docs.example.com/0.2/
|
|
|
|
docs.example.com/0.1/foo/ -> docs.example.com/0.2/foo/
|
|
|
|
docs.example.com/0.1/bar/ -> docs.example.com/0.2/bar/
|
|
|
|
```
|
|
|
|
|
|
|
|
=== "Old behavior"
|
|
|
|
|
|
|
|
```
|
|
|
|
docs.example.com/0.1/ -> docs.example.com/0.2/
|
|
|
|
docs.example.com/0.1/foo/ -> docs.example.com/0.2/
|
|
|
|
docs.example.com/0.1/bar/ -> docs.example.com/0.2/
|
|
|
|
```
|
|
|
|
|
2021-10-05 00:36:31 +03:00
|
|
|
<figure markdown>
|
|
|
|
<figcaption markdown>
|
2021-04-11 19:09:04 +03:00
|
|
|
|
|
|
|
A demo is worth a thousand words — check it out at
|
|
|
|
[squidfunk.github.io/mkdocs-material-example-versioning][4]
|
|
|
|
|
|
|
|
</figcaption>
|
|
|
|
</figure>
|
|
|
|
|
|
|
|
|
2020-10-25 18:14:02 +03:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
While this section outlines the basic workflow for publishing new versions,
|
2021-03-07 03:48:58 +03:00
|
|
|
it's best to check out the [official documentation][6] to make yourself familar
|
2020-10-25 18:14:02 +03:00
|
|
|
with [mike][1].
|
|
|
|
|
|
|
|
### Publishing a new version
|
|
|
|
|
2020-10-25 19:03:19 +03:00
|
|
|
If you want to publish a new version of your project documentation, choose a
|
2020-10-25 18:14:02 +03:00
|
|
|
version identifier and update the alias set as the default version with:
|
|
|
|
|
|
|
|
```
|
2020-10-25 19:03:19 +03:00
|
|
|
mike deploy --push --update-aliases 0.1 latest
|
2020-10-25 18:14:02 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Note that every version will be deployed as a subdirectory of your `site_url`,
|
|
|
|
e.g.:
|
|
|
|
|
2021-04-11 19:09:04 +03:00
|
|
|
- _docs.example.com/0.1/_
|
|
|
|
- _docs.example.com/0.2/_
|
2020-10-25 18:14:02 +03:00
|
|
|
- ...
|
2020-10-25 19:03:19 +03:00
|
|
|
|
|
|
|
### Setting a default version
|
|
|
|
|
|
|
|
When starting with [mike][1], 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:
|
|
|
|
|
|
|
|
```
|
|
|
|
mike set-default --push latest
|
|
|
|
```
|
|
|
|
|
|
|
|
When publishing a new version, [mike][1] will create a redirect in the root of
|
|
|
|
your project documentation to the version associated with the alias:
|
|
|
|
|
|
|
|
_docs.example.com_ :octicons-arrow-right-24: _docs.example.com/0.1_
|