From 7785ca87342c8932d0445605cdd0002f21733108 Mon Sep 17 00:00:00 2001 From: Kristaps Berzinch Date: Wed, 19 Jun 2024 10:09:49 -0400 Subject: [PATCH] Minify docs --- .github/workflows/build-artifact.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/build-artifact.yml b/.github/workflows/build-artifact.yml index d156254..1f9e5cb 100644 --- a/.github/workflows/build-artifact.yml +++ b/.github/workflows/build-artifact.yml @@ -16,6 +16,12 @@ jobs: - name: Register problem matchers run: echo "::add-matcher::.github/matchers.json" + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + check-latest: true + node-version: latest + - name: Setup Python uses: actions/setup-python@v5 with: @@ -36,6 +42,25 @@ jobs: - name: Build Sphinx docs run: poetry run sphinx-build -M dirhtml . _build + - name: Minify built docs + run: | + set -eux + npm install -g npm@latest + npx html-minifier --input-dir /docs/ --output-dir /docs/ --file-ext html --collapse-whitespace --collapse-inline-tag-whitespace --minify-css --minify-js --minify-urls ROOT_PATH_RELATIVE --remove-comments --remove-empty-attributes --conservative-collapse + find /docs/ -type f -size +0 | while read file; do + filename=$(basename -- "$file"); + extension="${filename##*.}"; + if [ "$extension" = "js" ]; then + npx terser "$file" --compress --output "$file"; + fi; + if [ "$extension" = "css" ]; then + npx clean-css-cli "$file" -O2 --output "$file"; + fi; + if [ "$extension" = "map" ]; then + rm -f "$file"; + fi; + done; + - name: Upload GitHub Pages artifact uses: actions/upload-pages-artifact@v3 with: