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 }}
|
{{ if .Params.featured_image }}
|
||||||
style="background-image: url(
|
style="background-image: url(
|
||||||
{{ with .Resources.GetMatch .Params.featured_image }}
|
{{ 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 -}}
|
{{- else -}}
|
||||||
{{- warnf "Featured image %s is not a page resource" .Params.featured_image -}}
|
{{- warnf "Featured image %s is not a page resource" .Params.featured_image -}}
|
||||||
{{- .Params.featured_image -}}
|
{{- .Params.featured_image -}}
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
style="display: none;"
|
style="display: none;"
|
||||||
src="
|
src="
|
||||||
{{- with .Resources.GetMatch .Params.featured_image -}}
|
{{- 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 -}}
|
{{- else -}}
|
||||||
{{- warnf "Featured image %s is not a page resource" .Params.featured_image -}}
|
{{- warnf "Featured image %s is not a page resource" .Params.featured_image -}}
|
||||||
{{- .Params.featured_image -}}
|
{{- .Params.featured_image -}}
|
||||||
|
|
|
@ -3,16 +3,17 @@
|
||||||
|
|
||||||
@params src Image media file.
|
@params src Image media file.
|
||||||
@params raw Force raw image only. Optional.
|
@params raw Force raw image only. Optional.
|
||||||
|
@params cacheBust Force cache busting. Optional.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- Variable assignment -->
|
<!-- Variable assignment -->
|
||||||
|
|
||||||
{{- $src := .src -}}
|
{{- $src := .src -}}
|
||||||
{{- $hint := default ( index $src.Params "hint" ) "" }}
|
{{- $hint := default ( index $src.Params "hint" ) "" }}
|
||||||
|
{{- $cacheBust := cond ( and ( isset . "cacheBust" ) .cacheBust ) "" ( md5 now.UnixNano ) -}}
|
||||||
{{- $format := cond ( and ( isset . "raw" ) .raw ) "" "webp" -}}
|
{{- $format := cond ( and ( isset . "raw" ) .raw ) "" "webp" -}}
|
||||||
{{- $isResizable := not ( in ( slice "svg" "gif" ) $src.MediaType.SubType ) -}}
|
{{- $isResizable := not ( in ( slice "svg" "gif" ) $src.MediaType.SubType ) -}}
|
||||||
|
|
||||||
|
|
||||||
<!-- Rendering -->
|
<!-- Rendering -->
|
||||||
|
|
||||||
<picture
|
<picture
|
||||||
|
@ -21,17 +22,17 @@
|
||||||
>
|
>
|
||||||
{{ if $isResizable -}}
|
{{ if $isResizable -}}
|
||||||
<source
|
<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 -}}
|
{{- if gt $src.Width 1200 -}}
|
||||||
<source
|
<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)"
|
media="(max-width: 1200px)"
|
||||||
/>
|
/>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if gt $src.Width 800 -}}
|
{{- if gt $src.Width 800 -}}
|
||||||
<source
|
<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)"
|
media="(max-width: 800px)"
|
||||||
/>
|
/>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -41,7 +42,7 @@
|
||||||
{{ if not $isResizable -}}
|
{{ if not $isResizable -}}
|
||||||
src="{{- $src.RelPermalink -}}"
|
src="{{- $src.RelPermalink -}}"
|
||||||
{{- else -}}
|
{{- 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 -}}"
|
width="{{- $src.Width -}}"
|
||||||
height="{{- $src.Height -}}"
|
height="{{- $src.Height -}}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
poster="
|
poster="
|
||||||
{{- if $src.Params.poster -}}
|
{{- if $src.Params.poster -}}
|
||||||
{{- $posterSrc := $.Page.Resources.GetMatch ( .Get $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 -}}
|
{{- else -}}
|
||||||
{{- erroridf "a11y-video-poster" "No poster defined for resource %q (%q)" $src.RelPermalink .page_file_path -}}
|
{{- erroridf "a11y-video-poster" "No poster defined for resource %q (%q)" $src.RelPermalink .page_file_path -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
style="display: none;"
|
style="display: none;"
|
||||||
src="
|
src="
|
||||||
{{- with ( $.pc.Resources.GetMatch . ) -}}
|
{{- with ( $.pc.Resources.GetMatch . ) -}}
|
||||||
{{- partialCached "images/get-image.html" ( dict "img" . ) .Title -}}
|
{{- partialCached "images/get-image.html" ( dict "img" . ) . -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- . -}}
|
{{- . -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
class="article-header__featured-image"
|
class="article-header__featured-image"
|
||||||
{{ with .pc.Params.featured_image }}
|
{{ with .pc.Params.featured_image }}
|
||||||
{{ with ( $.pc.Resources.GetMatch . ) }}
|
{{ 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 }}
|
{{ else }}
|
||||||
{{- if $.pc.Page.Resources -}}
|
{{- 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 -}}
|
{{- 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 link URI or Page Resource to wrap image in. Optional.
|
||||||
@params rel Force relationship value. Optional.
|
@params rel Force relationship value. Optional.
|
||||||
@params raw Force raw image only. Optional.
|
@params raw Force raw image only. Optional.
|
||||||
|
@params cacheBust Force cache busting. Optional.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- Variable assignment -->
|
<!-- Variable assignment -->
|
||||||
|
|
||||||
{{- $src := $.Page.Resources.GetMatch ( .Get "src" ) -}}
|
{{- $src := $.Page.Resources.GetMatch ( .Get "src" ) -}}
|
||||||
{{- $raw := default false ( .Get "raw" ) -}}
|
{{- $raw := default false ( .Get "raw" ) -}}
|
||||||
|
{{- $cacheBust := default false ( .Get "cacheBust" ) -}}
|
||||||
{{- $linkedResource := $.Page.Resources.GetMatch ( .Get "link" ) -}}
|
{{- $linkedResource := $.Page.Resources.GetMatch ( .Get "link" ) -}}
|
||||||
{{- $valid_rel_values := partialCached "util/get_valid_rel_values.html" . -}}
|
{{- $valid_rel_values := partialCached "util/get_valid_rel_values.html" . -}}
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@
|
||||||
<a href="{{- .Get "link" -}}">
|
<a href="{{- .Get "link" -}}">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- 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" -}}
|
{{- if .Get "link" -}}
|
||||||
</a>
|
</a>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
{{- $darkest = index (sort .Colors "Luminance") 0 -}}
|
{{- $darkest = index (sort .Colors "Luminance") 0 -}}
|
||||||
{{- $lightest = index (sort .Colors "Luminance" "desc") 0 -}}
|
{{- $lightest = index (sort .Colors "Luminance" "desc") 0 -}}
|
||||||
{{- end -}}
|
{{- 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 -}};"
|
background-color: {{ default ( default "#fff" $lightest ) .Params.bg -}};"
|
||||||
{{- else -}}
|
{{- 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 -}}
|
{{- 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