From 3a2a6482da5ba111b93a659da446c0fcfdcd5ebb Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Wed, 9 Jul 2025 21:22:16 +0200 Subject: [PATCH] fix: image caching cache key --- layouts/_partials/item-tile.html | 4 ++-- layouts/_partials/media/picture.html | 11 ++++++----- layouts/_partials/media/video.html | 2 +- layouts/_partials/single/main-header/item-tile.html | 4 ++-- layouts/_shortcodes/picture.html | 4 +++- layouts/cv/organisations/section.html | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/layouts/_partials/item-tile.html b/layouts/_partials/item-tile.html index 0ef309b..f6f93f4 100644 --- a/layouts/_partials/item-tile.html +++ b/layouts/_partials/item-tile.html @@ -34,7 +34,7 @@ {{ if .Params.featured_image }} style="background-image: url( {{ with .Resources.GetMatch .Params.featured_image }} - {{- partialCached "images/get-image.html" ( dict "img" . "size" "500x" ) ( printf "%s-500x" .Title ) -}} + {{- partialCached "images/get-image.html" ( dict "img" . "size" "500x" ) . "500x" -}} {{- else -}} {{- warnf "Featured image %s is not a page resource" .Params.featured_image -}} {{- .Params.featured_image -}} @@ -48,7 +48,7 @@ style="display: none;" src=" {{- with .Resources.GetMatch .Params.featured_image -}} - {{- partialCached "images/get-image.html" ( dict "img" . "size" "500x" ) ( printf "%s-500x" .Title ) -}} + {{- partialCached "images/get-image.html" ( dict "img" . "size" "500x" ) . "500x" -}} {{- else -}} {{- warnf "Featured image %s is not a page resource" .Params.featured_image -}} {{- .Params.featured_image -}} diff --git a/layouts/_partials/media/picture.html b/layouts/_partials/media/picture.html index cb26816..bd57a2f 100644 --- a/layouts/_partials/media/picture.html +++ b/layouts/_partials/media/picture.html @@ -3,16 +3,17 @@ @params src Image media file. @params raw Force raw image only. Optional. + @params cacheBust Force cache busting. Optional. --> {{- $src := .src -}} {{- $hint := default ( index $src.Params "hint" ) "" }} +{{- $cacheBust := cond ( and ( isset . "cacheBust" ) .cacheBust ) "" ( md5 now.UnixNano ) -}} {{- $format := cond ( and ( isset . "raw" ) .raw ) "" "webp" -}} {{- $isResizable := not ( in ( slice "svg" "gif" ) $src.MediaType.SubType ) -}} - {{ if $isResizable -}} {{- if gt $src.Width 1200 -}} {{- end -}} {{- if gt $src.Width 800 -}} {{- end -}} @@ -41,7 +42,7 @@ {{ if not $isResizable -}} src="{{- $src.RelPermalink -}}" {{- else -}} - src="{{- partialCached "images/get-image.html" ( dict "img" $src "format" $format ) $src.Title -}}" + src="{{- partialCached "images/get-image.html" ( dict "img" $src "format" $format ) $src $cacheBust -}}" width="{{- $src.Width -}}" height="{{- $src.Height -}}" {{- end }} diff --git a/layouts/_partials/media/video.html b/layouts/_partials/media/video.html index d635abf..8267918 100644 --- a/layouts/_partials/media/video.html +++ b/layouts/_partials/media/video.html @@ -16,7 +16,7 @@ poster=" {{- if $src.Params.poster -}} {{- $posterSrc := $.Page.Resources.GetMatch ( .Get $src.Params.poster ) -}} - {{- partialCached "images/get-image.html" ( dict "img" $posterSrc ) $posterSrc.Title -}} + {{- partialCached "images/get-image.html" ( dict "img" $posterSrc ) $posterSrc -}} {{- else -}} {{- erroridf "a11y-video-poster" "No poster defined for resource %q (%q)" $src.RelPermalink .page_file_path -}} {{- end -}} diff --git a/layouts/_partials/single/main-header/item-tile.html b/layouts/_partials/single/main-header/item-tile.html index 41654ca..3efc697 100644 --- a/layouts/_partials/single/main-header/item-tile.html +++ b/layouts/_partials/single/main-header/item-tile.html @@ -20,7 +20,7 @@ style="display: none;" src=" {{- with ( $.pc.Resources.GetMatch . ) -}} - {{- partialCached "images/get-image.html" ( dict "img" . ) .Title -}} + {{- partialCached "images/get-image.html" ( dict "img" . ) . -}} {{- else -}} {{- . -}} {{- end -}} @@ -37,7 +37,7 @@ class="article-header__featured-image" {{ with .pc.Params.featured_image }} {{ with ( $.pc.Resources.GetMatch . ) }} - style="background-image: url({{- partialCached "images/get-image.html" ( dict "img" . ) .Title -}})" + style="background-image: url({{- partialCached "images/get-image.html" ( dict "img" . ) . -}})" {{ else }} {{- if $.pc.Page.Resources -}} {{- errorf "No Page Resource found for src '%q' (%q).\n\n\tAvailable Page Resources are:\n\t\t%v" . $.pc.Page.File.Path $.pc.Page.Resources -}} diff --git a/layouts/_shortcodes/picture.html b/layouts/_shortcodes/picture.html index 5d977cc..c32a8ab 100644 --- a/layouts/_shortcodes/picture.html +++ b/layouts/_shortcodes/picture.html @@ -5,12 +5,14 @@ @params link URI or Page Resource to wrap image in. Optional. @params rel Force relationship value. Optional. @params raw Force raw image only. Optional. + @params cacheBust Force cache busting. Optional. --> {{- $src := $.Page.Resources.GetMatch ( .Get "src" ) -}} {{- $raw := default false ( .Get "raw" ) -}} +{{- $cacheBust := default false ( .Get "cacheBust" ) -}} {{- $linkedResource := $.Page.Resources.GetMatch ( .Get "link" ) -}} {{- $valid_rel_values := partialCached "util/get_valid_rel_values.html" . -}} @@ -39,7 +41,7 @@ {{- end -}} {{- end -}} -{{- partial "media/picture.html" ( dict "src" $src "raw" $raw ) -}} +{{- partial "media/picture.html" ( dict "src" $src "raw" $raw "cacheBust" $cacheBust ) -}} {{- if .Get "link" -}} {{- end -}} diff --git a/layouts/cv/organisations/section.html b/layouts/cv/organisations/section.html index d9343de..8779a1a 100644 --- a/layouts/cv/organisations/section.html +++ b/layouts/cv/organisations/section.html @@ -27,7 +27,7 @@ {{- $darkest = index (sort .Colors "Luminance") 0 -}} {{- $lightest = index (sort .Colors "Luminance" "desc") 0 -}} {{- end -}} - style="background-image: url({{- partialCached "images/get-image.html" ( dict "img" . ) .Title -}}); + style="background-image: url({{- partialCached "images/get-image.html" ( dict "img" . ) . -}}); background-color: {{ default ( default "#fff" $lightest ) .Params.bg -}};" {{- else -}} {{- errorf "No Page Resource found for src '%q' (%q).\n\n\tAvailable Page Resources are:\n\t\t%v" . $.Page.File.Path $.Page.Resources -}}