2020-07-16 22:31:39 +02:00
|
|
|
---
|
|
|
|
template: overrides/main.html
|
|
|
|
---
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
If you're already hosting your code on GitHub, [GitHub Pages][1] is certainly
|
|
|
|
the most convenient way to publish your project documentation. It's free of
|
|
|
|
charge and pretty easy to set up.
|
|
|
|
|
|
|
|
[1]: https://pages.github.com/
|
|
|
|
|
|
|
|
### with GitHub Actions
|
|
|
|
|
|
|
|
Using [GitHub Actions][2] you can automate the deployment of your project
|
|
|
|
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
|
|
|
|
|
|
|
``` yaml
|
|
|
|
name: ci
|
|
|
|
on:
|
2020-07-17 08:04:48 +02:00
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
2020-07-16 22:31:39 +02:00
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
- uses: actions/setup-python@v2
|
|
|
|
with:
|
|
|
|
python-version: 3.x
|
|
|
|
- run: pip install mkdocs-material
|
|
|
|
- run: mkdocs gh-deploy --force
|
|
|
|
```
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
=== "Insiders"
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
name: ci
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
- uses: actions/setup-python@v2
|
|
|
|
with:
|
|
|
|
python-version: 3.x
|
|
|
|
- run: pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
|
|
|
|
- run: mkdocs gh-deploy --force
|
|
|
|
env:
|
|
|
|
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
|
|
```
|
|
|
|
|
2020-07-16 22:31:39 +02: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>.github.io/<repository>`.
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
_Remember to set the_ `GH_TOKEN` _environment variable to the value of your
|
|
|
|
[personal access token][3] when using [Material for MkDocs Insiders][4], which
|
|
|
|
can be done using [secrets][5]._
|
|
|
|
|
2020-07-16 22:31:39 +02:00
|
|
|
[2]: https://github.com/features/actions
|
2020-08-30 11:49:05 +02:00
|
|
|
[3]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
|
|
|
|
[4]: insiders.md
|
|
|
|
[5]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
|
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
|
|
|
|
```
|
|
|
|
|
|
|
|
## GitLab Pages
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
If you're hosting your code on GitLab, deploying to [GitLab Pages][6] can be
|
|
|
|
done by using the [GitLab CI][7] task runner. At the root of your repository,
|
2020-07-16 22:31:39 +02:00
|
|
|
create a task definition named `.gitlab-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
|
|
|
|
|
|
|
``` yaml
|
|
|
|
image: python:latest
|
|
|
|
deploy:
|
|
|
|
stage: deploy
|
|
|
|
only:
|
|
|
|
- master
|
|
|
|
script:
|
|
|
|
- pip install mkdocs-material
|
|
|
|
- mkdocs build --site-dir public
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- public
|
|
|
|
```
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
=== "Insiders"
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
image: python:latest
|
|
|
|
deploy:
|
|
|
|
stage: deploy
|
|
|
|
only:
|
|
|
|
- master
|
|
|
|
script:
|
|
|
|
- pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
|
|
|
|
- mkdocs build --site-dir public
|
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- public
|
|
|
|
```
|
|
|
|
|
2020-07-16 22:31:39 +02: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>`.
|
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
_Remember to set the_ `GH_TOKEN` _environment variable to the value of your
|
|
|
|
[personal access token][3] when using [Material for MkDocs Insiders][4], which
|
|
|
|
can be done using [masked custom variables][8]._
|
2020-07-16 22:31:39 +02:00
|
|
|
|
2020-08-30 11:49:05 +02:00
|
|
|
[6]: https://gitlab.com/pages
|
|
|
|
[7]: https://docs.gitlab.com/ee/ci/
|
|
|
|
[8]: https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui
|