Skip to content

Commit

Permalink
Layout: Revert SVG inlining and compress SVGs
Browse files Browse the repository at this point in the history
  • Loading branch information
stephankoe committed Apr 12, 2024
1 parent c005cf4 commit dca70e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/hugo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions assets/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [
"../../../.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/!cai!jimmy/hugo-theme-stack/[email protected]/assets/*"
]
}
}
}
2 changes: 1 addition & 1 deletion assets/scss/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%);
}

Expand Down
9 changes: 1 addition & 8 deletions layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
{{- end -}}
{{- end -}}

{{- if $notSVG -}}
<img src="{{ $Permalink }}"
{{ with $Width }}width="{{ . }}"{{ end }}
{{ with $Height }}height="{{ . }}"{{ end }}
Expand All @@ -42,10 +41,4 @@
data-flex-grow="{{ div (mul $image.Width 100) $image.Height }}"
data-flex-basis="{{ div (mul $image.Width 240) $image.Height }}px"
{{ end }}
>
{{- else -}}
{{
replaceRE "(width|height)=\"([A-Za-z0-9,.-]*)?\"" "width=100% class=\"svg-diagram\"" $image.Content 2
| safeHTML
}}
{{- end -}}
>

0 comments on commit dca70e1

Please sign in to comment.