|
| 1 | +--- |
| 2 | +icon: lucide/layers-plus |
| 3 | +--- |
| 4 | + |
| 5 | +# Versioning |
| 6 | + |
| 7 | +Zensical allows to deploy and connect multiple versions of your project |
| 8 | +documentation on [GitHub Pages] by integrating with our fork of [mike], a tool |
| 9 | +that was originally designed for MkDocs which we adapted for Zensical – a bridge |
| 10 | +solution until we introduce [native versioning support]. |
| 11 | + |
| 12 | + [GitHub Pages]: ../publish-your-site.md#github-pages |
| 13 | + [mike]: https://github.com/squidfunk/mike |
| 14 | + [native versioning support]: https://zensical.org/about/roadmap/#versioning |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +We provide a fork of [mike] that you can install with `pip`: |
| 19 | + |
| 20 | +``` |
| 21 | +pip install git+https://github.com/squidfunk/mike.git |
| 22 | +``` |
| 23 | + |
| 24 | +This will make the `mike` executable available in your environment. |
| 25 | + |
| 26 | +!!! warning "This package is not published on PyPI" |
| 27 | + |
| 28 | + Note that installation requires `git`. Since we consider this a temporary solution, we do not plan to publish this package on PyPI, so you need to install it directly from GitHub. |
| 29 | + |
| 30 | +## Configuration |
| 31 | + |
| 32 | +### Versioning |
| 33 | + |
| 34 | +[mike] makes it easy to deploy multiple versions of your project documentation. |
| 35 | +The version selector can be enabled by setting the `provider` option to `mike`: |
| 36 | + |
| 37 | +=== "`zensical.toml`" |
| 38 | + |
| 39 | + ``` toml |
| 40 | + [project.extra.version] |
| 41 | + provider = "mike" |
| 42 | + ``` |
| 43 | + |
| 44 | +=== "`mkdocs.yml`" |
| 45 | + |
| 46 | + ``` yaml |
| 47 | + extra: |
| 48 | + version: |
| 49 | + provider: mike |
| 50 | + ``` |
| 51 | + |
| 52 | +### Version warning |
| 53 | + |
| 54 | +If you're using versioning, you might want to display a warning when the user |
| 55 | +visits any other version than the latest version. Using [theme extension], |
| 56 | +you can [override the `outdated` block][overriding blocks]: |
| 57 | + |
| 58 | +``` html |
| 59 | +{% extends "base.html" %} |
| 60 | + |
| 61 | +{% block outdated %} |
| 62 | + You're not viewing the latest version. |
| 63 | + <a href="{{ '../' ~ base_url }}"> <!-- (1)! --> |
| 64 | + <strong>Click here to go to latest.</strong> |
| 65 | + </a> |
| 66 | +{% endblock %} |
| 67 | +``` |
| 68 | + |
| 69 | +1. Given this value for the `href` attribute, the link will always redirect to |
| 70 | + the root of your site, which will then redirect to the latest version. This |
| 71 | + ensures that older versions of your site do not depend on a specific alias, |
| 72 | + e.g. `latest`, to allow for changing the alias later on without breaking |
| 73 | + earlier versions. |
| 74 | + |
| 75 | +This will render a version warning above the header. |
| 76 | + |
| 77 | +The default version is identified by the `latest` alias. If you wish to set |
| 78 | +another alias as the latest version, e.g. `stable`, add the following lines |
| 79 | +to your configuration: |
| 80 | + |
| 81 | +=== "`zensical.toml`" |
| 82 | + |
| 83 | + ``` toml |
| 84 | + [project.extra.version] |
| 85 | + default = "stable" # (1)! |
| 86 | + ``` |
| 87 | + |
| 88 | + 1. You can also define multiple aliases as the default version, e.g. `stable` |
| 89 | + and `development`. |
| 90 | + |
| 91 | + ``` toml |
| 92 | + [project.extra.version] |
| 93 | + default = ["stable", "development"] |
| 94 | + ``` |
| 95 | + |
| 96 | + Now every version that has the `stable` and `development` aliases will not |
| 97 | + display the version warning. |
| 98 | + |
| 99 | +=== "`mkdocs.yml`" |
| 100 | + |
| 101 | + ``` yaml |
| 102 | + extra: |
| 103 | + version: |
| 104 | + default: stable # (1)! |
| 105 | + ``` |
| 106 | + |
| 107 | + 1. You can also define multiple aliases as the default version, e.g. `stable` |
| 108 | + and `development`. |
| 109 | + |
| 110 | + ``` yaml |
| 111 | + extra: |
| 112 | + version: |
| 113 | + default: |
| 114 | + - stable |
| 115 | + - development |
| 116 | + ``` |
| 117 | + |
| 118 | + Now every version that has the `stable` and `development` aliases will not |
| 119 | + display the version warning. |
| 120 | + |
| 121 | +Make sure one alias matches the [default version], as this is where users are |
| 122 | +redirected to. |
| 123 | + |
| 124 | + [theme extension]: ../customization.md#extending-the-theme |
| 125 | + [overriding blocks]: ../customization.md#overriding-blocks |
| 126 | + [default version]: #setting-a-default-version |
| 127 | + |
| 128 | +### Version alias |
| 129 | + |
| 130 | +If you're using aliases for versioning, and want to show the version alias |
| 131 | +besides the version number, you can enable this feature by setting the `alias` |
| 132 | +option to `true`: |
| 133 | + |
| 134 | +=== "`zensical.toml`" |
| 135 | + |
| 136 | + ``` toml |
| 137 | + [project.extra.version] |
| 138 | + alias = true |
| 139 | + ``` |
| 140 | + |
| 141 | +=== "`mkdocs.yml`" |
| 142 | + |
| 143 | + ``` yaml |
| 144 | + extra: |
| 145 | + version: |
| 146 | + alias: true |
| 147 | + ``` |
| 148 | + |
| 149 | +## Usage |
| 150 | + |
| 151 | +While this section outlines the basic workflow for publishing new versions, |
| 152 | +it's best to check out [mike's documentation] to make yourself familiar |
| 153 | +with its mechanics. |
| 154 | + |
| 155 | + [mike's documentation]: https://github.com/jimporter/mike |
| 156 | + |
| 157 | +### Publishing a new version |
| 158 | + |
| 159 | +If you want to publish a new version of your project documentation, choose a |
| 160 | +version identifier and update the alias set as the default version with: |
| 161 | + |
| 162 | +``` |
| 163 | +mike deploy --push --update-aliases 0.1 latest |
| 164 | +``` |
| 165 | + |
| 166 | +Note that every version will be deployed as a subdirectory of your `site_url`, |
| 167 | +which you should set explicitly. For example, if your configuration contains: |
| 168 | + |
| 169 | +=== "`zensical.toml`" |
| 170 | + |
| 171 | + ``` toml |
| 172 | + [project] |
| 173 | + site_url = "https://docs.example.com/" # Trailing slash is recommended |
| 174 | + ``` |
| 175 | + |
| 176 | +=== "`mkdocs.yml`" |
| 177 | + |
| 178 | + ``` yaml |
| 179 | + site_url: 'https://docs.example.com/' # Trailing slash is recommended |
| 180 | + ``` |
| 181 | + |
| 182 | +the documentation will be published to URLs such as: |
| 183 | + |
| 184 | +- _docs.example.com/0.1/_ |
| 185 | +- _docs.example.com/0.2/_ |
| 186 | +- ... |
| 187 | + |
| 188 | +### Setting a default version |
| 189 | + |
| 190 | +When starting with [mike], a good idea is to set an alias as a default version, |
| 191 | +e.g. `latest`, and when publishing a new version, always update the alias to |
| 192 | +point to the latest version: |
| 193 | + |
| 194 | +``` |
| 195 | +mike set-default --push latest |
| 196 | +``` |
| 197 | + |
| 198 | +When publishing a new version, [mike] will create a redirect in the root of |
| 199 | +your project documentation to the version associated with the alias: |
| 200 | + |
| 201 | +_docs.example.com_ :octicons-arrow-right-24: _docs.example.com/0.1_ |
0 commit comments