From 2badbe26015fc1a24cd7909b3d59535a8c5a2879 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Fri, 8 Dec 2023 15:10:41 -0800 Subject: [PATCH] Use cache-busting partial instead of Fingerprint This gives files much smaller fingerprints, and supports caching. --- Makefile | 2 +- assets/manifest.webmanifest | 10 +++++----- layouts/_default/404.html | 2 +- layouts/_default/list.atom.xml | 8 ++++---- layouts/partials/cache-bust.html | 5 +++++ layouts/partials/head.html | 8 ++++---- layouts/shortcodes/audio.html | 4 ++-- layouts/shortcodes/indieweb-author.html | 3 +-- layouts/shortcodes/indieweb-icon.html | 16 ++++++++-------- layouts/shortcodes/picture.html | 20 ++++++++++---------- 10 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 layouts/partials/cache-bust.html diff --git a/Makefile b/Makefile index db03ebd..6b02119 100644 --- a/Makefile +++ b/Makefile @@ -189,5 +189,5 @@ lint-and-deploy-staging: deploy-envs: @$(MAKE) HUGO_FLAGS='--gc --ignoreCache' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs xhtmlize @$(MAKE) HUGO_FLAGS='--gc --ignoreCache' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs copy-to-xhtml - @$(MAKE) HUGO_FLAGS='' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs html-validate validate-html validate-json validate-feeds + @$(MAKE) HUGO_FLAGS='' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs validate-html validate-json validate-feeds @$(MAKE) SSHFLAGS='-o KexAlgorithms=curve25519-sha256@libssh.org' HUGO_FLAGS='' USER=seirdy@envs.net WWW_ROOT=/home/seirdy/public_html GEMINI_ROOT=/home/seirdy/public_gemini HUGO_BASEURL='https://envs.net/~seirdy/' OUTPUT_DIR=public_envs deploy diff --git a/assets/manifest.webmanifest b/assets/manifest.webmanifest index 4b3f135..cbf32c4 100644 --- a/assets/manifest.webmanifest +++ b/assets/manifest.webmanifest @@ -1,8 +1,8 @@ -{{- $192png := resources.Get "/favicon192.png" | resources.Fingerprint "md5" }} -{{- $512png := resources.Get "/favicon512.png" | resources.Fingerprint "md5" }} -{{- $1024svg := resources.Get "/favicon.svg" | resources.Fingerprint "md5" }} -{{- $maskablesvg := resources.Get "/maskable_android.svg" | resources.Fingerprint "md5" -}} -{{- $monochromesvg := resources.Get "/monochrome.svg" | resources.Fingerprint "md5" -}} +{{- $192png := partialCached "cache-bust.html" "/favicon192.png" "favicon192.png" }} +{{- $512png := partialCached "cache-bust.html" "/favicon512.png" "favicon512.png" }} +{{- $1024svg := partialCached "cache-bust.html" "/favicon.svg" "/favicon.svg" }} +{{- $maskablesvg := partial "cache-bust.html" "/maskable_android.svg" }} +{{- $monochromesvg := partial "cache-bust.html" "/monochrome.svg" }} { "name": "{{site.Title}}", "short_name": "Seirdy", diff --git a/layouts/_default/404.html b/layouts/_default/404.html index d7aed71..ad14866 100644 --- a/layouts/_default/404.html +++ b/layouts/_default/404.html @@ -17,7 +17,7 @@ {{ .Title }} {{ if not (in site.BaseURL ".onion") -}} -{{ $icon_svg := resources.Get "/favicon.svg" | resources.Fingerprint "md5" }} +{{ $icon_svg := partialCached "cache-bust.html" "/favicon.svg" "/favicon.svg" }} {{- printf `` $icon_svg.RelPermalink | safeHTML }} {{- end }} {{ $icon_192 := resources.Get "/favicon192.png" | resources.Fingerprint "md5" }} diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml index 4444411..9363eea 100644 --- a/layouts/_default/list.atom.xml +++ b/layouts/_default/list.atom.xml @@ -9,9 +9,9 @@ {{- if eq .Section "notes" -}} {{- $period = "hourly" -}} {{- end -}} -{{- $faviconSvg := resources.Get "/favicon.svg" | resources.Fingerprint "md5" -}} -{{- $image := resources.Get "/favicon192.png" | resources.Fingerprint "md5" -}} -{{- $atomLogo := resources.Get "/atom.svg" | resources.Fingerprint "md5" -}} +{{- $faviconSvg := partialCached "cache-bust.html" "/favicon.svg" "/favicon.svg" -}} +{{- $image := partialCached "cache-bust.html" "/favicon192.png" "/favicon192.png" -}} +{{- $atomLogo := partial "cache-bust.html" "/atom.svg" -}} {{- /*rejected http://backend.userland.com/creativeCommonsRssModule, as it's completely redundant with and rel-license. */ -}} http://activitystrea.ms/schema/1.0/{{ $type }} http://activitystrea.ms/schema/1.0/post {{- with .Params.image -}} - {{- $image = resources.Get (printf "/p/%s" . ) | resources.Fingerprint "md5" -}} + {{- $image := partial "cache-bust.html" (printf "/p/%s" . ) -}} {{- end -}} {{ with .Description -}} diff --git a/layouts/partials/cache-bust.html b/layouts/partials/cache-bust.html new file mode 100644 index 0000000..9aff8d7 --- /dev/null +++ b/layouts/partials/cache-bust.html @@ -0,0 +1,5 @@ +{{ $resource := resources.Get . -}} +{{- $target_path_formatStr := (replaceRE `(\.[^\.]*)$` ".%d$1" .) -}} +{{- $cacheBuster := $resource.Content | crypto.FNV32a -}} +{{- $target_path := printf $target_path_formatStr $cacheBuster -}} +{{- return resources.Copy $target_path $resource -}} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index f714f7d..3e1536b 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -55,10 +55,10 @@ {{- end -}} {{ if not (in site.BaseURL ".onion") -}} - {{ $icon_svg := resources.Get "/favicon.svg" | resources.Fingerprint "md5" }} + {{ $icon_svg := partialCached "cache-bust.html" "/favicon.svg" "/favicon.svg" }} {{- printf `` $icon_svg.RelPermalink | safeHTML }} {{- end }} - {{ $icon_192 := resources.Get "/favicon192.png" | resources.Fingerprint "md5" }} + {{ $icon_192 := partialCached "cache-bust.html" "/favicon192.png" "/favicon192.png" }} {{- printf `` $icon_192.RelPermalink | safeHTML -}} @@ -70,10 +70,10 @@ {{- end -}} - {{- $og_image := resources.Get "/favicon512.png" | resources.Fingerprint "md5" -}} + {{- $og_image := partialCached "cache-bust.html" "/favicon512.png" "/favicon512.png" -}} {{- $og_image_alt := "" -}} {{- with .Params.image -}} - {{- $og_image = resources.Get (printf "/p/%s" . ) | resources.Fingerprint "md5" -}} + {{- $og_image = partial "cache-bust.html" (printf "/p/%s" .) -}} {{- end -}} {{- with .Params.image_alt -}} {{- $og_image_alt = . -}} diff --git a/layouts/shortcodes/audio.html b/layouts/shortcodes/audio.html index 7b3219d..497cc87 100644 --- a/layouts/shortcodes/audio.html +++ b/layouts/shortcodes/audio.html @@ -21,14 +21,14 @@ > {{ with $opus -}} {{- $download_url = $opus.RelPermalink -}} - {{ $opus_src := . | resources.Fingerprint "md5" -}} + {{ $opus_src := partial "cache-bust.html" . -}} {{ end -}} {{ with $mp3 -}} {{- $download_url = $mp3.RelPermalink -}} - {{ $mp3_src := . | resources.Fingerprint "md5" -}} + {{ $mp3_src := partial "cache-bust.html" . -}} diff --git a/layouts/shortcodes/indieweb-author.html b/layouts/shortcodes/indieweb-author.html index 518bdea..e7a54ee 100644 --- a/layouts/shortcodes/indieweb-author.html +++ b/layouts/shortcodes/indieweb-author.html @@ -1,5 +1,4 @@ -{{- $favicon := resources.Get "/favicon.png" -}} -{{- $favicon_base64 := $favicon.Content | base64Encode -}}