Initialize MkDocs
Setting Up Your Project
CLI/Bash
Please note how we make use of Gitpod CLI (Command-line interface) or Bash throughout the process.
Initial Setup
-
Use Code Institute's Gitpod Full Template: Use the template from Code Institute found at Gitpod Full Template to initialize your Gitpod workspace.
Note: Don't forget to install Django to avoid specific errors such as
ValueError: ZoneInfo keys may not be absolute paths, got: /UTC
.
Installing MkDocs and Dependencies
-
Install MkDocs: To create your project documentation.
-
If you don't see the
docs
folder automatically created then you need to initialize mkdocs manually: -
Install MkDocs Material: This is the theme used for MkDocs.
-
Test MkDocs: Ensure everything is working as expected, if not, reinstall Django, mkdocs & mkdocs-material.
-
Important: Remove
.github/
from the.gitignore
file. It is important to set up the docs with Github Pages: -
Push Changes to GitHub: follow the standards!
Setting Up GitHub Actions
Create GitHub Actions Workflow
-
Create
.github
Folder: This folder will contain your GitHub workflows. -
Navigate to
.github
Folder -
Create
workflows
Folder: This folder will contain your workflow files. -
Go Back to Main Directory
-
Create
ci.yml
File: This file defines your CI (Continuous Integration)/CD (Continuous Deployment/Delivery) pipeline.Add the Following Content to
ci.yml
:name: ci on: push: branches: - master - main permissions: contents: write jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: 3.x - uses: actions/cache@v2 with: key: ${{ github.ref }} path: .cache - run: pip install mkdocs-material - run: pip install pillow cairosvg - run: mkdocs gh-deploy --force
-
Move
ci.yml
toworkflows
Directory: This makes sure GitHub Actions recognizes your workflow. -
Push Changes to GitHub
Final Configuration on GitHub
- Navigate to Your Repository's Settings: Then go to the "Pages" section.
- Configure Build and Deployment: Under 'Build and Deployment', select 'Deploy from a branch' then choose the
source
as'gh-pages'
do not change the/ (root)
and click the 'Save' button. - Find URL: Go back to GitHub Actions and check the process
pages build and deployment
once it is completed (green). Access it to find your URL at thebuild-deploy
level.
Style Your Documentation
Enhance your documentation with the following sample code by updating the mkdocs.yml
file:
Your GitHub Actions workflow should start automatically. It usually takes a few minutes to deploy. You can check the progress in the "Actions" tab on your GitHub repository. Once the action is complete, your MkDocs documentation will be available on your GitHub Pages URL.
Logo & Favicon
First, ensure that you have created a folder named assets/
within the mkdocs folder. This should be the subfolder where index.md
is located, not the main one. Within the assets/
folder, create additional subfolders, such as img/
. Your goal is to have the path docs/assets/img/logo.png
for your logo and favicon.
Next, go to your mkdocs.yml
file and add the following lines under the theme:
entry:
Update Mkdocs & Mkdocs Material
If you want to update all extensions please use the following code:
Install MathJax
MathJax and KaTeX are two popular libraries for displaying mathematical content in browsers. Although both libraries offer similar functionality, they use different syntaxes and have different configuration options. This documentation site provides information on how to integrate them with Material for MkDocs easily. For more visit Mkdocs Material
MathJax is a powerful and flexible library that supports multiple input formats, such as LaTeX, MathML, AsciiMath, as well as various output formats like HTML, SVG, MathML. To use MathJax within your project, add the following lines to your mkdocs.yml:
- First, add this Javascript code:
// LOCATION: docs/javascripts/mathjax.js
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};
document$.subscribe(() => {
MathJax.typesetPromise()
})
- Second, add this yml code:
# LOCATION: mkdocs.yml
markdown_extensions:
- pymdownx.arithmatex:
generic: true
extra_javascript:
- javascripts/mathjax.js
- https://polyfill.io/v3/polyfill.min.js?features=es6
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
Bug - ZoneInfo
To avoid the ValueError: ZoneInfo keys may not be absolute paths, got: /UTC
please install Django as described above.
Multi-Language Setup
This documentation provides a comprehensive guide for managing multi-language documentation using MkDocs. It outlines the steps to create and maintain a well-organized, multi-lingual documentation site.
-
Language-Specific Subfolders Creation:
Create subfolders in the
docs
directory for each language. For example, English and German:-
en/
-
de/
Store language-specific files in these folders for organizational purposes.
-
-
Updating
.yml
Files for Indexing:Update the
.yml
files to reflect the structure of your documentation:-
mkdocs.yml
(Home:en/index.md
) -
mkdocs_de.yml
(Home:de/index.md
) -
mkdocs_landing.yml
(Welcome:index.md
)
-
-
Landing Page Configuration:
Maintain
index.md
in thedocs
directory as a universal landing page, redirecting users to the appropriate language version.mkdocs_landing.yml
(Welcome:index.md
)
-
Configuration for the Default Language (English):
Maintain the primary
mkdocs.yml
for the default language (English in this case). The configuration includes various settings like site name, navigation, theme, extensions, and copyright details.
# GENERAL & NAVs
site_name: Frank Arellano - Plexosoft
nav:
# English
- Home: en/index.md
- EN: en/en.md
# THEME
theme:
language: en
logo: assets/img/logo.png
font:
text: Roboto
code: Roboto Mono
name: material
features:
- navigation.tabs
- navigation.sections
- toc.integrate
- navigation.top
- search.suggest
- search.highlight
- content.tabs.link
- content.code.annotation
- content.code.copy
palette:
- scheme: default
toggle:
icon: material/toggle-switch
name: Switch to light mode
primary: white
accent: indigo
- scheme: slate
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
primary: black
accent: yellow
# EXTRA
extra:
alternate:
- name: English
link: /plexosoft_services/1/en # absolute URL IMPORTANT related to ci.yml (gh-pages)
lang: en
- name: Deutsch
link: /plexosoft_services/2/de # absolute URL IMPORTANT related to ci.yml (gh-pages)
lang: de
social:
- icon: fontawesome/brands/github-alt
link: https://github.com/plexoio
- icon: fontawesome/brands/twitter
link: https://twitter.com/plexoio
- icon: fontawesome/brands/linkedin
link: https://www.linkedin.com/in/arellanofrank/
# EXTENSIONS
markdown_extensions:
- tables
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.inlinehilite
- pymdownx.snippets
- admonition
- pymdownx.arithmatex:
generic: true
- footnotes
- pymdownx.details
- pymdownx.superfences
- pymdownx.mark
- attr_list
- pymdownx.critic
- pymdownx.caret
- pymdownx.keys
- pymdownx.tilde
- pymdownx.tabbed:
alternate_style: true
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
copyright: |
© 2023 by <a href="https://github.com/plexoio" target="_blank" rel="noopener">Frank Arellano</a>
using
<a href="https://www.mkdocs.org/" target="_blank" rel="noopener">MkDocs</a>
- Creating and Configuring Additional Language Files:
Duplicate the
mkdocs.yml
file for other languages, modifying it accordingly. This includes changing the language settings, navigation paths, and any language-specific content.
# GENERAL & NAVs
site_name: Frank Arellano - Plexosoft
nav:
# DEUTSCH
- Home: de/index.md
- DE: de/de.md
# THEME
theme:
language: de
logo: assets/img/logo.png
font:
text: Roboto
code: Roboto Mono
name: material
features:
- navigation.tabs
- navigation.sections
- toc.integrate
- navigation.top
- search.suggest
- search.highlight
- content.tabs.link
- content.code.annotation
- content.code.copy
palette:
- scheme: default
toggle:
icon: material/toggle-switch
name: Switch to light mode
primary: white
accent: indigo
- scheme: slate
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
primary: black
accent: yellow
# EXTRA
extra:
alternate:
- name: English
link: /plexosoft_services/1/en # absolute URL IMPORTANT related to ci.yml (gh-pages)
lang: en
- name: Deutsch
link: /plexosoft_services/2/de # absolute URL IMPORTANT related to ci.yml (gh-pages)
lang: de
social:
- icon: fontawesome/brands/github-alt
link: https://github.com/plexoio
- icon: fontawesome/brands/twitter
link: https://twitter.com/plexoio
- icon: fontawesome/brands/linkedin
link: https://www.linkedin.com/in/arellanofrank/
# EXTENSIONS
markdown_extensions:
- tables
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.inlinehilite
- pymdownx.snippets
- admonition
- pymdownx.arithmatex:
generic: true
- footnotes
- pymdownx.details
- pymdownx.superfences
- pymdownx.mark
- attr_list
- pymdownx.critic
- pymdownx.caret
- pymdownx.keys
- pymdownx.tilde
- pymdownx.tabbed:
alternate_style: true
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
copyright: |
© 2023 by <a href="https://github.com/plexoio" target="_blank" rel="noopener">Frank Arellano</a>
using
<a href="https://www.mkdocs.org/" target="_blank" rel="noopener">MkDocs</a>
-
Optional Configuration for
mkdocs_landing.yml
: Create/Update themkdocs_landing.yml
if necessary to align with the multi-language setup. -
Adjusting Absolute Paths: Note that some paths in the configuration are absolute, based on your GitHub page or domain. Modify these paths to ensure proper functionality.
-
Modifying
ci.yml
for GitHub Actions: Update theci.yml
file to logically reflect the multi-language documentation setup. This includes building and deploying different language versions of the site.
name: ci
on:
push:
branches:
- master
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
- uses: actions/cache@v2
with:
key: ${{ github.ref }}
path: .cache
- run: pip install mkdocs-material
- run: pip install pillow cairosvg
# Landing Page
- name: Build Landing Page
run: mkdocs build --config-file mkdocs_landing.yml --site-dir site
# Build English version
- name: Build English Page
run: mkdocs build --config-file mkdocs.yml --site-dir site/1
# Build German version
- name: Build German site
run: mkdocs build --config-file mkdocs_de.yml --site-dir site/2
# Deploy to GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
- Ongoing Updates and Maintenance:
Regularly update both the
mkdocs.yml
(main) and other language files likemkdocs_de.yml
andmkdocs_landing.yml
to keep all versions synchronized with the same features and updates.