From 663c0aab256e82e2e76c6e63442d7d2328edeff1 Mon Sep 17 00:00:00 2001 From: Leon Xu Date: Sun, 29 Nov 2026 14:46:04 -0800 Subject: [PATCH] Add build-time image optimization (pngquant/oxipng/jpegoptim) to pipeline --- .gitea/workflows/deploy.yml | 9 +++++++++ README.md | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 9323394..b46341b 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -48,6 +48,15 @@ jobs: - name: Build site run: hexo generate + # Best-effort image optimization at build time: originals in source/ + # stay untouched, only the built artifact shrinks (~58% on this site). + - name: Optimize images + run: | + apt-get update -qq && apt-get install -y -qq pngquant oxipng jpegoptim + find public -type f -name '*.png' -exec sh -c 'pngquant --quality=80-95 --strip --force --skip-if-larger --output "$1" "$1"; oxipng -o max -q "$1"' _ {} \; + find public -type f \( -name '*.jpg' -o -name '*.jpeg' \) -exec jpegoptim --max=90 --strip-all --threshold=5 -q {} \; + echo "site size after optimization: $(du -sh public | cut -f1)" + - name: Upload site artifact uses: actions/upload-artifact@v4 with: diff --git a/README.md b/README.md index afca5d7..44a53a3 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,9 @@ The [deploy workflow](.gitea/workflows/deploy.yml) runs four gated stages: 1. **lint** — checks all Markdown in `source/` and `scaffolds/` with `markdownlint-cli2` (house style codified in `.markdownlint-cli2.jsonc`) 2. **build** — checks out the repo, sets up Node 22, runs `yarn install - --frozen-lockfile` and `hexo generate` (~171 files, ~9 MB into `public/`), - then uploads the site as a workflow artifact + --frozen-lockfile` and `hexo generate`, optimizes every PNG/JPEG in the + built output with pngquant/oxipng/jpegoptim (~58% smaller images, originals + in `source/` untouched), then uploads the site as a workflow artifact 3. **test** — validates the built artifact without touching production: structural checks (index, theme assets, file count) plus a serving smoke test that requests the homepage, a real post page, and the stylesheet