From dca70e11238050110b6402afe57a8ba96eea6c03 Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 12 Apr 2024 19:54:54 +0800 Subject: [PATCH] Layout: Revert SVG inlining and compress SVGs --- .github/workflows/hugo.yml | 8 ++++++++ assets/jsconfig.json | 10 ++++++++++ assets/scss/custom.scss | 2 +- layouts/_default/_markup/render-image.html | 9 +-------- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 assets/jsconfig.json diff --git a/.github/workflows/hugo.yml b/.github/workflows/hugo.yml index 7db27ae..0b72c1b 100644 --- a/.github/workflows/hugo.yml +++ b/.github/workflows/hugo.yml @@ -32,6 +32,10 @@ jobs: && sudo dpkg -i ${{ runner.temp }}/hugo.deb - name: Install Dart Sass run: sudo snap install dart-sass + - name: Install compression dependencies + run: | + sudo snap install svgo + && sudo apt install scour - name: Checkout uses: actions/checkout@v4 with: @@ -47,6 +51,10 @@ jobs: && pip install ${{ runner.temp }}/markdown-preprocessor - name: Run Markdown preprocessor run: "[[ -f assets/bibliography.json ]] && find content/post -type f -iname '*.md' -exec preprocess-citations -i --bibliography=assets/bibliography.json {} \\; || echo 'No bibliography found'" + - name: Compress SVGs + run: | + find . -type f -iname '*.svg' -exec bash -c 'scour {} | svgo --multipass - -o {}.min' \; + && find . -type f -iname '*.svg.min' -exec sh -c 'for f; do mv "$f" "${f%.min}"; done' sh {} + - name: Build with Hugo env: # For maximum backward compatibility with Hugo modules diff --git a/assets/jsconfig.json b/assets/jsconfig.json new file mode 100644 index 0000000..fb2c4db --- /dev/null +++ b/assets/jsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": [ + "../../../.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/v3@v3.21.0/assets/*" + ] + } + } +} \ No newline at end of file diff --git a/assets/scss/custom.scss b/assets/scss/custom.scss index 5d15b47..99f9d3d 100644 --- a/assets/scss/custom.scss +++ b/assets/scss/custom.scss @@ -7,7 +7,7 @@ /* Invert the colors of images in dark theme */ -html[data-scheme="dark"] svg.svg-diagram { +html[data-scheme="dark"] img.svg { filter: invert(73.828125%); } diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index aa69b9d..7a11697 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -25,7 +25,6 @@ {{- end -}} {{- end -}} -{{- if $notSVG -}} -{{- else -}} -{{ - replaceRE "(width|height)=\"([A-Za-z0-9,.-]*)?\"" "width=100% class=\"svg-diagram\"" $image.Content 2 - | safeHTML -}} -{{- end -}} \ No newline at end of file +> \ No newline at end of file