2020-07-16 23:31:39 +03:00
|
|
|
# Publishing your site
|
|
|
|
|
|
|
|
The great thing about hosting project documentation in a `git` repository is
|
2020-07-22 20:11:22 +03:00
|
|
|
the ability to deploy it automatically when new changes are pushed. MkDocs
|
2020-07-16 23:31:39 +03:00
|
|
|
makes this ridiculously simple.
|
|
|
|
|
|
|
|
## GitHub Pages
|
|
|
|
|
2021-10-10 23:32:32 +03:00
|
|
|
If you're already hosting your code on GitHub, [GitHub Pages] is certainly
|
2020-07-16 23:31:39 +03:00
|
|
|
the most convenient way to publish your project documentation. It's free of
|
|
|
|
charge and pretty easy to set up.
|
|
|
|
|
2021-10-10 23:32:32 +03:00
|
|
|
[GitHub Pages]: https://pages.github.com/
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
### with GitHub Actions
|
|
|
|
|
2021-10-10 23:32:32 +03:00
|
|
|
Using [GitHub Actions] you can automate the deployment of your project
|
2020-07-16 23:31:39 +03: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 12:49:05 +03:00
|
|
|
=== "Material for MkDocs"
|
2020-07-16 23:31:39 +03:00
|
|
|
|
2021-07-18 18:57:45 +03:00
|
|
|
``` yaml
|
2021-12-11 16:30:07 +03:00
|
|
|
name: ci # (1)!
|
2020-07-16 23:31:39 +03:00
|
|
|
on:
|
2020-07-17 09:04:48 +03:00
|
|
|
push:
|
2022-01-08 12:56:08 +03:00
|
|
|
branches:
|
|
|
|
- master # (2)!
|
2020-11-30 19:39:28 +03:00
|
|
|
- main
|
2022-11-25 13:23:18 +03:00
|
|
|
permissions:
|
|
|
|
contents: write
|
2020-07-16 23:31:39 +03:00
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-11-25 13:23:18 +03:00
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- uses: actions/setup-python@v4
|
2020-07-16 23:31:39 +03:00
|
|
|
with:
|
|
|
|
python-version: 3.x
|
2023-01-21 19:51:17 +03:00
|
|
|
- uses: actions/cache@v2
|
|
|
|
with:
|
|
|
|
key: ${{ github.ref }}
|
|
|
|
path: .cache
|
2021-12-11 16:30:07 +03:00
|
|
|
- run: pip install mkdocs-material # (3)!
|
2020-07-16 23:31:39 +03:00
|
|
|
- run: mkdocs gh-deploy --force
|
|
|
|
```
|
|
|
|
|
2021-12-27 15:50:27 +03:00
|
|
|
1. You can change the name to your liking.
|
2021-06-17 09:51:16 +03:00
|
|
|
|
2021-12-27 15:50:27 +03: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 09:51:16 +03:00
|
|
|
|
2021-12-27 15:50:27 +03:00
|
|
|
3. This is the place to install further [MkDocs plugins] or Markdown
|
|
|
|
extensions with `pip` to be used during the build:
|
2021-06-17 09:51:16 +03:00
|
|
|
|
|
|
|
``` sh
|
|
|
|
pip install \
|
|
|
|
mkdocs-material \
|
|
|
|
mkdocs-awesome-pages-plugin \
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
2020-08-30 12:49:05 +03:00
|
|
|
=== "Insiders"
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
name: ci
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
2020-11-30 19:39:28 +03:00
|
|
|
- main
|
2022-11-25 13:23:18 +03:00
|
|
|
permissions:
|
|
|
|
contents: write
|
2020-08-30 12:49:05 +03:00
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
2021-03-21 19:14:32 +03:00
|
|
|
if: github.event.repository.fork == false
|
2020-08-30 12:49:05 +03:00
|
|
|
steps:
|
2022-11-25 13:23:18 +03:00
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- uses: actions/setup-python@v4
|
2020-08-30 12:49:05 +03:00
|
|
|
with:
|
|
|
|
python-version: 3.x
|
2023-01-21 19:51:17 +03:00
|
|
|
- uses: actions/cache@v2
|
|
|
|
with:
|
|
|
|
key: ${{ github.ref }}
|
|
|
|
path: .cache
|
|
|
|
- run: apt-get install pngquant # (1)!
|
2020-08-30 12:49:05 +03:00
|
|
|
- run: pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
|
|
|
|
- run: mkdocs gh-deploy --force
|
|
|
|
env:
|
2023-01-21 19:51:17 +03:00
|
|
|
GH_TOKEN: ${{ secrets.GH_TOKEN }} # (2)!
|
2020-08-30 12:49:05 +03:00
|
|
|
```
|
|
|
|
|
2023-01-21 19:51:17 +03:00
|
|
|
1. This step is only necessary if you want to use the
|
|
|
|
[built-in optimize plugin] to automatically compress images.
|
|
|
|
|
|
|
|
2. Remember to set the `GH_TOKEN` environment variable to the value of your
|
2021-10-10 23:32:32 +03:00
|
|
|
[personal access token] when deploying [Insiders], which can be done
|
|
|
|
using [GitHub secrets].
|
|
|
|
|
2020-11-30 19:39:28 +03:00
|
|
|
Now, when a new commit is pushed to either the `master` or `main` branches,
|
2021-01-31 21:23:28 +03:00
|
|
|
the static site is automatically built and deployed. Push your changes to see
|
|
|
|
the workflow in action.
|
2020-07-16 23:31:39 +03:00
|
|
|
|
2022-04-02 16:10:50 +03: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 19:02:02 +03:00
|
|
|
|
2020-07-16 23:31:39 +03:00
|
|
|
Your documentation should shortly appear at `<username>.github.io/<repository>`.
|
|
|
|
|
2021-10-10 23:32:32 +03: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-01-21 19:51:17 +03:00
|
|
|
[built-in optimize plugin]: setup/building-an-optimized-site.md#built-in-optimize-plugin
|
2021-10-10 23:32:32 +03:00
|
|
|
[GitHub secrets]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
|
2021-11-13 14:13:45 +03:00
|
|
|
[publishing source branch]: https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site
|
2020-07-16 23:31:39 +03: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
|
|
|
|
```
|
|
|
|
|
|
|
|
## GitLab Pages
|
|
|
|
|
2021-10-10 23:32:32 +03: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 23:31:39 +03:00
|
|
|
|
2020-08-30 12:49:05 +03:00
|
|
|
=== "Material for MkDocs"
|
2020-07-16 23:31:39 +03:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
image: python:latest
|
2020-11-27 23:01:49 +03:00
|
|
|
pages:
|
2020-07-16 23:31:39 +03:00
|
|
|
stage: deploy
|
|
|
|
script:
|
|
|
|
- pip install mkdocs-material
|
|
|
|
- mkdocs build --site-dir public
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- public
|
2022-11-24 00:00:52 +03:00
|
|
|
rules:
|
|
|
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
2020-07-16 23:31:39 +03:00
|
|
|
```
|
|
|
|
|
2020-08-30 12:49:05 +03:00
|
|
|
=== "Insiders"
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
image: python:latest
|
2020-12-21 19:38:58 +03:00
|
|
|
pages:
|
2020-08-30 12:49:05 +03:00
|
|
|
stage: deploy
|
2021-12-27 15:50:27 +03:00
|
|
|
script: # (1)!
|
2020-08-30 12:49:05 +03:00
|
|
|
- pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
|
|
|
|
- mkdocs build --site-dir public
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- public
|
2022-11-24 00:00:52 +03:00
|
|
|
rules:
|
|
|
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
2020-08-30 12:49:05 +03:00
|
|
|
```
|
|
|
|
|
2021-12-27 15:50:27 +03:00
|
|
|
1. Remember to set the `GH_TOKEN` environment variable to the value of your
|
2021-10-10 23:32:32 +03:00
|
|
|
[personal access token] when deploying [Insiders], which can be done
|
|
|
|
using [masked custom variables].
|
|
|
|
|
2020-07-16 23:31:39 +03:00
|
|
|
Now, when a new commit is pushed to `master`, the static site is automatically
|
|
|
|
built and deployed. Commit and push the file to your repository to see the
|
|
|
|
workflow in action.
|
|
|
|
|
|
|
|
Your documentation should shortly appear at `<username>.gitlab.io/<repository>`.
|
|
|
|
|
2021-10-10 23:32:32 +03: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
|