fix: image caching cache key
This commit is contained in:
parent
fa3c57be79
commit
3a2a6482da
6 changed files with 15 additions and 12 deletions
|
@ -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 -}}
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
|
||||
@params src Image media file.
|
||||
@params raw Force raw image only. Optional.
|
||||
@params cacheBust Force cache busting. Optional.
|
||||
-->
|
||||
|
||||
<!-- Variable assignment -->
|
||||
|
||||
{{- $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 ) -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<picture
|
||||
|
@ -21,17 +22,17 @@
|
|||
>
|
||||
{{ if $isResizable -}}
|
||||
<source
|
||||
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "same" "format" $format ) $src.Title -}}"
|
||||
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "same" "format" $format ) $src $cacheBust -}}"
|
||||
/>
|
||||
{{- if gt $src.Width 1200 -}}
|
||||
<source
|
||||
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "1200x" "format" $format ) ( printf "%s-1200x" $src.Title ) -}}"
|
||||
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "1200x" "format" $format ) $src "1200x" $cacheBust -}}"
|
||||
media="(max-width: 1200px)"
|
||||
/>
|
||||
{{- end -}}
|
||||
{{- if gt $src.Width 800 -}}
|
||||
<source
|
||||
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "800x" "format" $format ) ( printf "%s-800x" $src.Title ) -}}"
|
||||
srcset="{{- partialCached "images/get-image.html" ( dict "img" $src "size" "800x" "format" $format ) $src "800x" $cacheBust -}}"
|
||||
media="(max-width: 800px)"
|
||||
/>
|
||||
{{- 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 }}
|
||||
|
|
|
@ -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 -}}
|
||||
|
|
|
@ -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 -}}
|
||||
|
|
|
@ -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.
|
||||
-->
|
||||
|
||||
<!-- Variable assignment -->
|
||||
|
||||
{{- $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 @@
|
|||
<a href="{{- .Get "link" -}}">
|
||||
{{- 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" -}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
|
|
|
@ -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 -}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue