diff options
author | tdro <tdro@noreply.example.com> | 2022-06-09 21:07:52 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-06-09 21:07:52 -0400 |
commit | 99b3afaf045e9f67c4fc18c30e5cd05f883752e5 (patch) | |
tree | 8d614b5584c45d7f346cbda68a3678964252e7e1 /themes/default/layouts/_default/_markup/render-image.html | |
parent | 024c6aeaaa0130e5b044a4c390d5016f7fff0798 (diff) | |
download | canory-99b3afaf045e9f67c4fc18c30e5cd05f883752e5.tar.gz canory-99b3afaf045e9f67c4fc18c30e5cd05f883752e5.tar.bz2 canory-99b3afaf045e9f67c4fc18c30e5cd05f883752e5.zip |
themes/default/layouts/_default/_markup/render-image: Let gallery walk see
Track files in gallery. Might as well optimise source sets.
Try webp first, else fall back to given image type.
Diffstat (limited to 'themes/default/layouts/_default/_markup/render-image.html')
-rw-r--r-- | themes/default/layouts/_default/_markup/render-image.html | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/themes/default/layouts/_default/_markup/render-image.html b/themes/default/layouts/_default/_markup/render-image.html index 05a5c7d..8f09192 100644 --- a/themes/default/layouts/_default/_markup/render-image.html +++ b/themes/default/layouts/_default/_markup/render-image.html @@ -1,47 +1,60 @@ {{- $source := $.Destination | safeURL -}} {{- $public := print "public/" $source -}} -{{- $remoteImage := resources.GetRemote $source -}} -{{- $dimensions := "600x" -}} +{{- $remote := resources.GetRemote $source -}} +{{- $local := "" -}} {{- $width := "" -}} {{- $height := "" -}} {{- $cache := "" -}} +{{- $dimensions := "600x" -}} -{{- with $remoteImage -}} +{{- with $remote -}} {{- with .Err -}} {{- if fileExists $public -}} - {{- $localImage := imageConfig $public -}} - {{- with $localImage -}} - {{- $width = .Width -}} - {{- $height = .Height -}} + {{- $local = resources.Get $public -}} + {{- with $local -}} + {{- $local = .Content | resources.FromString (print "/data/static/images/" (. | urlize)) }} {{- end -}} {{ $source = print ("" | absURL) $source }} {{- else -}} - {{- $source = print "/images/404.png" -}} - {{- $404image := imageConfig (print "static/" $source) -}} + {{- $404origin := print "/images/404.png" -}} + {{- $404image := imageConfig (print "static/" $404origin) -}} {{- with $404image -}} {{- $width = .Width -}} {{- $height = .Height -}} {{- end -}} - {{ $source = print ("" | absURL) $source }} + {{ $source = print ("" | absURL) $404origin }} {{- end -}} {{- else -}} - {{- $width = .Width -}} - {{- $height = .Height -}} - {{- $cache = .Content | resources.FromString (print "/data/static/images/" (. | urlize)) -}} - {{- $cache = ($cache.Resize $dimensions).Permalink -}} + {{- $cache = .Content | resources.FromString (print $.Page.Section "/media/" (. | urlize)) -}} {{ end }} {{ end }} - {{- /* This comment removes trailing newlines and white spaces. */ -}} <figure> <a href="{{ $source }}"> - <img loading="lazy" - src="{{ or $cache $source }}" - alt="{{ $.Text | htmlUnescape }}" - title="{{ $.Text | htmlUnescape }}" - width="{{ $width }}" - height="{{ $height }}" - /> + <picture> + {{- with $local }} + <source srcset="{{- ($local.Resize (print $dimensions " webp")).RelPermalink -}}" type="image/webp" /> + {{- $local = $local.Resize $dimensions }} + {{- $width = $local.Width -}} + {{- $height = $local.Height -}} + {{- end }} + {{- with $cache }} + {{- $cache = .Content | resources.FromString (print "/data/static/images/" (. | urlize)) }} + <source srcset="{{- ($cache.Resize (print $dimensions " webp")).RelPermalink -}}" type="image/webp" /> + {{- $cache = .Content | resources.FromString (. | urlize) -}} + {{- $cache = $cache.Resize $dimensions }} + {{- $width = $cache.Width -}} + {{- $height = $cache.Height -}} + {{- $cache = $cache.RelPermalink }} + {{- end }} + <img loading="lazy" + src="{{ or $cache $source }}" + alt="{{ $.Text | htmlUnescape }}" + title="{{ $.Text | htmlUnescape }}" + width="{{ $width }}" + height="{{ $height }}" + /> + </picture> </a> <figcaption> {{ with $.Title -}} @@ -50,8 +63,8 @@ Image/Picture {{ end -}} <br> - {{ with $cache }} Cache: {{ print "[Link](" . ")" | markdownify }} · {{ end }} - Source: {{ print "[Link](" $source ")" | markdownify }} + Index: {{ with $cache }} {{ print "[Cache](" . ")" | markdownify }} · {{ end }} + {{ print "[Source](" $source ")" | markdownify }} </figcaption> </figure> {{- /* This comment removes trailing newlines and white spaces. */ -}} |