2020-07-16 22:31:39 +02:00
|
|
|
# Publishing your site
|
|
|
|
|
|
|
|
The great thing about hosting project documentation in a `git` repository is
|
2020-07-22 19:11:22 +02:00
|
|
|
the ability to deploy it automatically when new changes are pushed. MkDocs
|
2020-07-16 22:31:39 +02:00
|
|
|
makes this ridiculously simple.
|
|
|
|
|
|
|
|
## GitHub Pages
|
|
|
|
|
2021-10-10 22:32:32 +02:00
|
|
|
If you're already hosting your code on GitHub, [GitHub Pages] is certainly
|
2020-07-16 22:31:39 +02:00
|
|
|
the most convenient way to publish your project documentation. It's free of
|
|
|
|
charge and pretty easy to set up.
|
|
|
|
|
2021-10-10 22:32:32 +02:00
|
|
|
[GitHub Pages]: https://pages.github.com/
|
2020-07-16 22:31:39 +02:00
|
|
|
|
|
|
|
### with GitHub Actions
|
|
|
|
|
2021-10-10 22:32:32 +02:00
|
|
|
Using [GitHub Actions] you can automate the deployment of your project
|
2020-07-16 22:31:39 +02:00
|
|
|
documentation. At the root of your repository, create a new GitHub Actions
|
|
|
|
workflow, e.g. `.github/workflows/ci.yml`, and copy and paste the following
|
|
|
|
contents:
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
=== "Material for MkDocs"
|
2020-07-16 22:31:39 +02:00
|
|
|
|
2021-07-18 17:57:45 +02:00
|
|
|
``` yaml
|
2021-12-11 14:30:07 +01:00
|
|
|
name: ci # (1)!
|
2020-07-16 22:31:39 +02:00
|
|
|
on:
|
2020-07-17 08:04:48 +02:00
|
|
|
push:
|
2022-01-08 10:56:08 +01:00
|
|
|
branches:
|
|
|
|
- master # (2)!
|
2020-11-30 17:39:28 +01:00
|
|
|
- main
|
2022-11-25 11:23:18 +01:00
|
|
|
permissions:
|
|
|
|
contents: write
|
2020-07-16 22:31:39 +02:00
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-09-20 00:11:58 +02:00
|
|
|
- uses: actions/checkout@v4
|
2023-11-14 23:01:25 +01:00
|
|
|
- name: Configure Git Credentials
|
|
|
|
run: |
|
|
|
|
git config user.name github-actions[bot]
|
|
|
|
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
2024-01-31 16:08:26 +01:00
|
|
|
- uses: actions/setup-python@v5
|
2020-07-16 22:31:39 +02:00
|
|
|
with:
|
|
|
|
python-version: 3.x
|
2023-05-03 07:55:45 +02:00
|
|
|
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV # (3)!
|
2024-01-31 16:08:26 +01:00
|
|
|
- uses: actions/cache@v4
|
2023-01-21 17:51:17 +01:00
|
|
|
with:
|
2023-05-03 07:55:45 +02:00
|
|
|
key: mkdocs-material-${{ env.cache_id }}
|
2023-01-21 17:51:17 +01:00
|
|
|
path: .cache
|
2023-04-30 23:14:04 +02:00
|
|
|
restore-keys: |
|
|
|
|
mkdocs-material-
|
2023-05-02 14:47:30 +02:00
|
|
|
- run: pip install mkdocs-material # (4)!
|
2020-07-16 22:31:39 +02:00
|
|
|
- run: mkdocs gh-deploy --force
|
|
|
|
```
|
|
|
|
|
2023-09-15 09:25:50 +02:00
|
|
|
1. You can change the name to your liking.
|
2021-06-17 08:51:16 +02:00
|
|
|
|
2021-12-27 13:50:27 +01:00
|
|
|
2. At some point, GitHub renamed `master` to `main`. If your default branch
|
|
|
|
is named `master`, you can safely remove `main`, vice versa.
|
2021-06-17 08:51:16 +02:00
|
|
|
|
2023-05-03 07:55:45 +02:00
|
|
|
3. Store the `cache_id` environmental variable to access it later during cache
|
|
|
|
`key` creation. The name is case-sensitive, so be sure to align it with `${{ env.cache_id }}`.
|
|
|
|
|
|
|
|
- The `--utc` option makes sure that each workflow runner uses the same time zone.
|
2023-09-15 09:25:50 +02:00
|
|
|
- The `%V` format assures a cache update once a week.
|
|
|
|
- You can change the format to `%F` to have daily cache updates.
|
2023-05-03 07:55:45 +02:00
|
|
|
|
|
|
|
You can read the [manual page] to learn more about the formatting options of the `date` command.
|
2023-05-02 14:47:30 +02:00
|
|
|
|
|
|
|
4. This is the place to install further [MkDocs plugins] or Markdown
|
2021-12-27 13:50:27 +01:00
|
|
|
extensions with `pip` to be used during the build:
|
2021-06-17 08:51:16 +02:00
|
|
|
|
|
|
|
``` sh
|
|
|
|
pip install \
|
|
|
|
mkdocs-material \
|
|
|
|
mkdocs-awesome-pages-plugin \
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
=== "Insiders"
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
name: ci
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
2020-11-30 17:39:28 +01:00
|
|
|
- main
|
2022-11-25 11:23:18 +01:00
|
|
|
permissions:
|
|
|
|
contents: write
|
2020-08-30 11:49:05 +02:00
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
2021-03-21 17:14:32 +01:00
|
|
|
if: github.event.repository.fork == false
|
2020-08-30 11:49:05 +02:00
|
|
|
steps:
|
2023-09-20 00:11:58 +02:00
|
|
|
- uses: actions/checkout@v4
|
2023-11-14 23:01:25 +01:00
|
|
|
- name: Configure Git Credentials
|
|
|
|
run: |
|
|
|
|
git config user.name github-actions[bot]
|
|
|
|
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
2024-02-01 12:24:20 +01:00
|
|
|
- uses: actions/setup-python@v5
|
2020-08-30 11:49:05 +02:00
|
|
|
with:
|
|
|
|
python-version: 3.x
|
2023-05-03 07:55:45 +02:00
|
|
|
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
2024-02-01 12:24:20 +01:00
|
|
|
- uses: actions/cache@v4
|
2023-01-21 17:51:17 +01:00
|
|
|
with:
|
2023-05-03 07:55:45 +02:00
|
|
|
key: mkdocs-material-${{ env.cache_id }}
|
2023-01-21 17:51:17 +01:00
|
|
|
path: .cache
|
2023-04-30 23:14:04 +02:00
|
|
|
restore-keys: |
|
|
|
|
mkdocs-material-
|
2023-01-21 17:51:17 +01:00
|
|
|
- run: apt-get install pngquant # (1)!
|
2020-08-30 11:49:05 +02:00
|
|
|
- run: pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
|
|
|
|
- run: mkdocs gh-deploy --force
|
|
|
|
env:
|
2023-01-21 17:51:17 +01:00
|
|
|
GH_TOKEN: ${{ secrets.GH_TOKEN }} # (2)!
|
2020-08-30 11:49:05 +02:00
|
|
|
```
|
|
|
|
|
2023-01-21 17:51:17 +01:00
|
|
|
1. This step is only necessary if you want to use the
|
|
|
|
[built-in optimize plugin] to automatically compress images.
|
|
|
|
|
2024-07-09 10:27:01 +02:00
|
|
|
2. Remember to set the `GH_TOKEN` repository secret to the value of your
|
2021-10-10 22:32:32 +02:00
|
|
|
[personal access token] when deploying [Insiders], which can be done
|
|
|
|
using [GitHub secrets].
|
|
|
|
|
2020-11-30 17:39:28 +01:00
|
|
|
Now, when a new commit is pushed to either the `master` or `main` branches,
|
2021-01-31 19:23:28 +01:00
|
|
|
the static site is automatically built and deployed. Push your changes to see
|
|
|
|
the workflow in action.
|
2020-07-16 22:31:39 +02:00
|
|
|
|
2022-04-02 15:10:50 +02:00
|
|
|
If the GitHub Page doesn't show up after a few minutes, go to the settings of
|
|
|
|
your repository and ensure that the [publishing source branch] for your GitHub
|
|
|
|
Page is set to `gh-pages`.
|
2021-11-10 17:02:02 +01:00
|
|
|
|
2020-07-16 22:31:39 +02:00
|
|
|
Your documentation should shortly appear at `<username>.github.io/<repository>`.
|
|
|
|
|
2021-10-10 22:32:32 +02:00
|
|
|
[GitHub Actions]: https://github.com/features/actions
|
|
|
|
[MkDocs plugins]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins
|
|
|
|
[personal access token]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
|
|
|
|
[Insiders]: insiders/index.md
|
2023-09-15 09:25:50 +02:00
|
|
|
[built-in optimize plugin]: plugins/optimize.md
|
2021-10-10 22:32:32 +02:00
|
|
|
[GitHub secrets]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
|
2021-11-13 12:13:45 +01:00
|
|
|
[publishing source branch]: https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site
|
2023-05-03 07:55:45 +02:00
|
|
|
[manual page]: https://man7.org/linux/man-pages/man1/date.1.html
|
2020-07-16 22:31:39 +02:00
|
|
|
|
|
|
|
### with MkDocs
|
|
|
|
|
|
|
|
If you prefer to deploy your project documentation manually, you can just invoke
|
|
|
|
the following command from the directory containing the `mkdocs.yml` file:
|
|
|
|
|
|
|
|
```
|
|
|
|
mkdocs gh-deploy --force
|
|
|
|
```
|
|
|
|
|
2023-11-02 11:52:33 +01:00
|
|
|
This will build your documentation and deploy it to a branch
|
|
|
|
`gh-pages` in your repository. See [this overview in the MkDocs
|
|
|
|
documentation] for more information. For a description of the
|
|
|
|
arguments, see [the documentation for the command].
|
|
|
|
|
|
|
|
[this overview in the MkDocs documentation]: https://www.mkdocs.org/user-guide/deploying-your-docs/#project-pages
|
|
|
|
[the documentation for the command]: https://www.mkdocs.org/user-guide/cli/#mkdocs-gh-deploy
|
|
|
|
|
2020-07-16 22:31:39 +02:00
|
|
|
## GitLab Pages
|
|
|
|
|
2021-10-10 22:32:32 +02:00
|
|
|
If you're hosting your code on GitLab, deploying to [GitLab Pages] can be done
|
|
|
|
by using the [GitLab CI] task runner. At the root of your repository, create a
|
|
|
|
task definition named `.gitlab-ci.yml` and copy and paste the following
|
|
|
|
contents:
|
2020-07-16 22:31:39 +02:00
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
=== "Material for MkDocs"
|
2020-07-16 22:31:39 +02:00
|
|
|
|
|
|
|
``` yaml
|
2020-11-27 21:01:49 +01:00
|
|
|
pages:
|
2020-07-16 22:31:39 +02:00
|
|
|
stage: deploy
|
2023-10-23 09:32:24 +02:00
|
|
|
image: python:latest
|
2020-07-16 22:31:39 +02:00
|
|
|
script:
|
|
|
|
- pip install mkdocs-material
|
|
|
|
- mkdocs build --site-dir public
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- public
|
2022-11-23 22:00:52 +01:00
|
|
|
rules:
|
|
|
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
2020-07-16 22:31:39 +02:00
|
|
|
```
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
=== "Insiders"
|
|
|
|
|
|
|
|
``` yaml
|
2020-12-21 17:38:58 +01:00
|
|
|
pages:
|
2020-08-30 11:49:05 +02:00
|
|
|
stage: deploy
|
2023-10-23 09:32:24 +02:00
|
|
|
image: python:latest
|
2021-12-27 13:50:27 +01:00
|
|
|
script: # (1)!
|
2020-08-30 11:49:05 +02:00
|
|
|
- pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
|
|
|
|
- mkdocs build --site-dir public
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- public
|
2022-11-23 22:00:52 +01:00
|
|
|
rules:
|
|
|
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
2020-08-30 11:49:05 +02:00
|
|
|
```
|
|
|
|
|
2024-07-09 10:27:01 +02:00
|
|
|
1. Remember to set the `GH_TOKEN` repository secret to the value of your
|
2021-10-10 22:32:32 +02:00
|
|
|
[personal access token] when deploying [Insiders], which can be done
|
|
|
|
using [masked custom variables].
|
|
|
|
|
2023-10-24 12:11:41 +02:00
|
|
|
Now, when a new commit is pushed to the [default branch] (typically `master` or
|
|
|
|
`main`), the static site is automatically built and deployed. Commit and push
|
|
|
|
the file to your repository to see the workflow in action.
|
2020-07-16 22:31:39 +02:00
|
|
|
|
|
|
|
Your documentation should shortly appear at `<username>.gitlab.io/<repository>`.
|
|
|
|
|
2023-03-09 20:29:29 +01:00
|
|
|
## Other
|
|
|
|
|
|
|
|
Since we can't cover all possible platforms, we rely on community contributed
|
|
|
|
guides that explain how to deploy websites built with Material for MkDocs to
|
|
|
|
other providers:
|
|
|
|
|
|
|
|
<div class="mdx-columns" markdown>
|
|
|
|
|
2024-07-06 11:06:04 +02:00
|
|
|
- [:material-microsoft-azure-devops: Azure][Azure]
|
2023-03-09 20:29:29 +01:00
|
|
|
- [:simple-cloudflarepages: Cloudflare Pages][Cloudflare Pages]
|
|
|
|
- [:simple-digitalocean: DigitalOcean][DigitalOcean]
|
2024-01-19 16:32:34 +01:00
|
|
|
- [:material-airballoon-outline: Fly.io][Flyio]
|
2023-03-09 20:29:29 +01:00
|
|
|
- [:simple-netlify: Netlify][Netlify]
|
|
|
|
- [:simple-vercel: Vercel][Vercel]
|
2024-01-22 00:52:38 +01:00
|
|
|
- [:simple-codeberg: Codeberg Pages][Codeberg Pages]
|
2023-03-09 20:29:29 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2021-10-10 22:32:32 +02:00
|
|
|
[GitLab Pages]: https://gitlab.com/pages
|
|
|
|
[GitLab CI]: https://docs.gitlab.com/ee/ci/
|
|
|
|
[masked custom variables]: https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui
|
2023-10-24 12:11:41 +02:00
|
|
|
[default branch]: https://docs.gitlab.com/ee/user/project/repository/branches/default.html
|
2023-03-09 20:29:29 +01:00
|
|
|
[Azure]: https://bawmedical.co.uk/t/publishing-a-material-for-mkdocs-site-to-azure-with-automatic-branch-pr-preview-deployments/763
|
|
|
|
[Cloudflare Pages]: https://www.starfallprojects.co.uk/projects/deploy-host-docs/deploy-mkdocs-material-cloudflare/
|
|
|
|
[DigitalOcean]: https://www.starfallprojects.co.uk/projects/deploy-host-docs/deploy-mkdocs-material-digitalocean-app-platform/
|
2024-01-18 16:16:02 +01:00
|
|
|
[Flyio]: https://documentation.breadnet.co.uk/cloud/fly/mkdocs-on-fly/
|
2024-09-06 08:31:08 +02:00
|
|
|
[Netlify]: https://deborahwrites.com/projects/deploy-host-docs/deploy-mkdocs-material-netlify/
|
2023-03-09 20:29:29 +01:00
|
|
|
[Vercel]: https://www.starfallprojects.co.uk/projects/deploy-host-docs/deploy-mkdocs-material-vercel/
|
2023-11-06 13:47:51 +01:00
|
|
|
[Codeberg Pages]: https://andre601.ch/blog/2023/11-05-using-codeberg-pages/
|