Site Deployment¶
As said previously, Mkdocs allows conversion of .md
to HTML
, CSS
, and JS
files in order to create and deploy websites. Below are the possible approaches.
Site Deployment with Github¶
Assuming that your repository is in github, when an Mkdocs repository is created, simply type
1 |
|
Just follow the prompt, and it will automatically deploy your website in github pages. No other complication needed, this command will handle the following steps:
- Generation of website files
- Deployment with Github Pages
Automatic Site Deployment with Github Action¶
This is a configuration which allows your documentation from github to auto-deploy to the github pages. You might not want to run mkdocs gh-deploy
everytime you have new changes.
Why do I need this?
Let me give you an example, for this documentation it is hosted at https://uwasystemhealth.github.io/shl-mkdocs-tutorial-and-template/. If this thing is configured, then whenever you modify the github repository, it automatically redeploys in github pages.
How do I do this?¶
If you look closely in the repository, there is a file .github/workflows/main.yml
. Copy this file over to you repository. The content of it is roughly like below. Note that you have to change 2 lines highlighted to the path of your documentation.
Example of Path that you will have to change
If in the scenario that your repository is just documentation, which means that your mkdocs.yml
file is in the root, then you don't have to change anything.
However, there are cases where you have a monorepo - a type of repository that contains multiple files such as for example in a software project, there are the documentation files, and source code files. It is quite common to have a file structure that looks like this:
1 2 3 4 5 6 7 8 9 |
|
This means that you will have to change the one highlighted. From the example above here, the correct lines changes are:
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
to key: ${{ runner.os }}-pip-${{ hashFiles('**/mkdocs/requirements.txt') }}
and
python3 -m pip install -r ./requirements.txt
to python3 -m pip install -r ./mkdocs/requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
Custom Domain Name¶
In the scenario that you like a custom domain name such as https://www.tutorial-mkdocs.systemhealthlab.com , follow this documentation.
Simplified instructions:
- Go to the domain registar, in my case Cloudflare
- Register a "CNAME" of the domain/subdomain going towards
<organisation/githubname>.github.io
(eg.uwasystemhealth.github.io
) - Add a
CNAME
file with the name of the domain/subdomain in the/docs
folder - Give the
CNAME
file a content of the subdomain name (eg.tutorial-mkdocs.systemhealthlab.com
)
Custom Site Deployment¶
Let say you don't want to deploy it in github pages. You would like to deploy it elsewhere such as your own server or a VPS. Be aware that this portion is a little bit technical, and may not even be what you do in a regular basis or not necessary if you already deployed it with Github Pages. You have to type this command
1 |
|
This will create the /site
folder which contains your website files. Now you would have to setup a server application that serves static files such as NGINX
or Apache
server app. After setting this up, copy the contents of the /site
folder into the static file folder.