Skip to content

Commit

Permalink
improve mkdocs build perf
Browse files Browse the repository at this point in the history
  • Loading branch information
copdips committed Nov 9, 2024
1 parent b78e860 commit 7c6bb19
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:

steps:
- name: Checkout repository
# https://squidfunk.github.io/mkdocs-material/blog/2023/09/22/using-git-sparse-checkout-for-faster-documentation-builds/
uses: actions/checkout@v4
with:
fetch-depth: 0
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ build:
@echo "${BOLD}${YELLOW}mkdocs build:${NORMAL}"
${PYTHON} -m mkdocs build -s

serve:
run:
@echo "${BOLD}${YELLOW}mkdocs serve:${NORMAL}"
${PYTHON} -m mkdocs build -s && ${PYTHON} -m mkdocs serve

run: serve
${PYTHON} -m mkdocs serve --dirty

update-venv:
@echo "${BOLD}${YELLOW}update venv:${NORMAL}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ categories:
comments: true
date:
created: 2023-12-16
updated: 2024-11-10
description: ''
---

Expand Down Expand Up @@ -135,3 +136,9 @@ Code action view Source is bound to `master` branch by default, not `main` branc
Jekyll uses `gh-pages` branch to publish blog, but I used GitHub actions within Mkdocs, so I didn't need to use `gh-pages` branch. To use GitHub actions, I went to my repository at https://github.com/copdips/copdips.github.io/, entered `Settings` -> `Pages`, and set Github Actions as `Source`.

My GitHub Actions for blog publishing can be found [here](https://github.com/copdips/copdips.github.io/blob/main/.github/workflows/build_and_deploy.yml).

## Performance

When previewing the blog locally, add the `--dirty` flag like `python -m mkdocs serve --dirty` to build only the changed files, which can speed up the build process. Using `python -m` is helpful when, for example, [custom pymdownx scripts](../2023/2023-12-17-rendering-csv-as-markdown-table-in-mkdocs-material.md) are required.

For a deeper understanding of the build time, we can use [this tips](https://github.com/mkdocs/mkdocs/issues/3695#issuecomment-2094373134).
3 changes: 1 addition & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ plugins:
paths: [..]
- mkdocs-video
- glightbox
- minify:
minify_html: true
- minify_html
- git-committers:
enabled: !ENV [CI, false]
repository: copdips/copdips.github.io
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ mkdocstrings-python
mkdocs-video
mkdocs-glightbox
mkdocs-rss-plugin
# use minify-html instead of minify to boost build speed
# https://github.com/mkdocs/mkdocs/issues/3695#issuecomment-2094395638
mkdocs-minify-html-plugin

0 comments on commit 7c6bb19

Please sign in to comment.