Skip to content

Commit 7c6bb19

Browse files
committed
improve mkdocs build perf
1 parent b78e860 commit 7c6bb19

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

.github/workflows/build_and_deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525

2626
steps:
2727
- name: Checkout repository
28+
# https://squidfunk.github.io/mkdocs-material/blog/2023/09/22/using-git-sparse-checkout-for-faster-documentation-builds/
2829
uses: actions/checkout@v4
2930
with:
3031
fetch-depth: 0

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ build:
2626
@echo "${BOLD}${YELLOW}mkdocs build:${NORMAL}"
2727
${PYTHON} -m mkdocs build -s
2828

29-
serve:
29+
run:
3030
@echo "${BOLD}${YELLOW}mkdocs serve:${NORMAL}"
31-
${PYTHON} -m mkdocs build -s && ${PYTHON} -m mkdocs serve
32-
33-
run: serve
31+
${PYTHON} -m mkdocs serve --dirty
3432

3533
update-venv:
3634
@echo "${BOLD}${YELLOW}update venv:${NORMAL}"

docs/posts/2023/2023-12-16-migrating-my-blog-from-jekyll-minimal-mistakes-to-mkdocs-material.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ categories:
99
comments: true
1010
date:
1111
created: 2023-12-16
12+
updated: 2024-11-10
1213
description: ''
1314
---
1415

@@ -135,3 +136,9 @@ Code action view Source is bound to `master` branch by default, not `main` branc
135136
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`.
136137

137138
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).
139+
140+
## Performance
141+
142+
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.
143+
144+
For a deeper understanding of the build time, we can use [this tips](https://github.com/mkdocs/mkdocs/issues/3695#issuecomment-2094373134).

mkdocs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ plugins:
154154
paths: [..]
155155
- mkdocs-video
156156
- glightbox
157-
- minify:
158-
minify_html: true
157+
- minify_html
159158
- git-committers:
160159
enabled: !ENV [CI, false]
161160
repository: copdips/copdips.github.io

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ mkdocstrings-python
88
mkdocs-video
99
mkdocs-glightbox
1010
mkdocs-rss-plugin
11+
# use minify-html instead of minify to boost build speed
12+
# https://github.com/mkdocs/mkdocs/issues/3695#issuecomment-2094395638
13+
mkdocs-minify-html-plugin

0 commit comments

Comments
 (0)