1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-12-18 10:25:58 +01:00
mkdocs-material/docs/publishing-your-site.md

163 lines
4.6 KiB
Markdown
Raw Normal View History

---
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
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:
=== "Material for MkDocs"
2021-07-18 17:57:45 +02:00
``` yaml
2021-06-17 08:51:16 +02:00
name: ci # (1)
on:
push:
2021-06-17 08:51:16 +02:00
branches: # (2)
- master
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x
2021-06-17 08:51:16 +02:00
- run: pip install mkdocs-material # (3)
- run: mkdocs gh-deploy --force
```
2021-06-17 08:51:16 +02:00
1. You can change the name to your liking.
2. At some point, GitHub renamed `master` to `main`. If your default branch
is named `master`, you can safely remove `main`, vice versa.
3. This is the place to install further [MkDocs plugins][3] or Markdown
extensions with `pip` to be used during the build:
``` sh
pip install \
mkdocs-material \
mkdocs-awesome-pages-plugin \
...
```
=== "Insiders"
``` yaml
name: ci
on:
push:
branches:
- master
- main
jobs:
deploy:
runs-on: ubuntu-latest
2021-03-21 17:14:32 +01:00
if: github.event.repository.fork == false
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 }}
```
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.
Your documentation should shortly appear at `<username>.github.io/<repository>`.
_Remember to set the_ `GH_TOKEN` _environment variable to the value of your
2021-06-17 08:51:16 +02:00
[personal access token][4] when deploying [Insiders][5], which can be done
using [secrets][6]._
[2]: https://github.com/features/actions
2021-06-17 08:51:16 +02:00
[3]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins
[4]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
[5]: insiders/index.md
[6]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
### 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-06-17 08:51:16 +02:00
If you're hosting your code on GitLab, deploying to [GitLab Pages][7] can be
done by using the [GitLab CI][8] task runner. At the root of your repository,
create a task definition named `.gitlab-ci.yml` and copy and paste the
following contents:
=== "Material for MkDocs"
``` yaml
image: python:latest
2020-11-27 21:01:49 +01:00
pages:
stage: deploy
only:
- master
script:
- pip install mkdocs-material
- mkdocs build --site-dir public
artifacts:
paths:
- public
```
=== "Insiders"
``` yaml
image: python:latest
2020-12-21 17:38:58 +01:00
pages:
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
```
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>`.
_Remember to set the_ `GH_TOKEN` _environment variable to the value of your
2021-06-17 08:51:16 +02:00
[personal access token][4] when deploying [Insiders][5], which can be done
using [masked custom variables][9]._
2021-06-17 08:51:16 +02:00
[7]: https://gitlab.com/pages
[8]: https://docs.gitlab.com/ee/ci/
[9]: https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui