aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2023-11-06 20:15:38 -0500
committertdro <tdro@noreply.example.com>2023-11-06 20:15:38 -0500
commit72f3e6e848f0a965118b0b9cab894bb5b862c29b (patch)
tree9ee4df4e47aa29e5670a23ffabffea20986296d9 /themes/default/layouts/_default
parentdb793dde95bf546089e1fee8857a9f9510e6990c (diff)
downloadcanory-72f3e6e848f0a965118b0b9cab894bb5b862c29b.tar.gz
canory-72f3e6e848f0a965118b0b9cab894bb5b862c29b.tar.bz2
canory-72f3e6e848f0a965118b0b9cab894bb5b862c29b.zip
themes/default/layouts/_default/_markup/render-image: Resolve types
Diffstat (limited to 'themes/default/layouts/_default')
-rw-r--r--themes/default/layouts/_default/_markup/render-image.html27
1 files changed, 19 insertions, 8 deletions
diff --git a/themes/default/layouts/_default/_markup/render-image.html b/themes/default/layouts/_default/_markup/render-image.html
index 39720dc..97dbbbb 100644
--- a/themes/default/layouts/_default/_markup/render-image.html
+++ b/themes/default/layouts/_default/_markup/render-image.html
@@ -3,9 +3,10 @@
{{- $height := "" -}}
{{- $srcset := "" -}}
{{- $colors := "" -}}
+{{- $type := "" -}}
{{- $source := $.Destination | safeURL -}}
{{- $public := print "public/" $source -}}
-{{- $fetch := print (urls.Parse $source).Scheme "://" (urls.Parse $source).Host (urls.Parse $source).RequestURI -}}
+{{- $fetch := print (urls.Parse $source).Scheme "://" (urls.Parse $source).Host (urls.Parse $source).RequestURI -}}
{{- $figcaption := "Image/Picture" -}}
{{- $orientation := "landscape" -}}
{{- $dimensions := "600x360" -}}
@@ -15,6 +16,10 @@
{{- $storage := print $author "/media/" $immutable -}}
{{- $cached := fileExists (print "public/" $storage ".webp") -}}
+{{- $moderns := slice ".webp" ".avif" -}}
+{{- $fallbacks := slice ".png" ".jpg" ".gif" ".jpeg" ".svg" ".apng" ".jfif" ".pjpeg" ".pjp" -}}
+{{- $mimes := slice "image/avif" "image/webp" "image/apng" "image/gif" "image/jpeg" "image/png" "image/svg+xml" -}}
+
{{- if not $cached -}}
{{- with $remote := cond (default true $.Page.Site.Params.site.offline) false (resources.GetRemote $fetch) -}}
{{- with .Err -}}
@@ -29,12 +34,12 @@
{{- $width = $local.Width -}}
{{- $height = $local.Height -}}
{{- $colors = $local.Colors -}}
- {{- $cache = $local.Permalink -}}
+ {{- $cache = $local.Permalink -}}
{{- end -}}
{{- $source = print ("" | absURL) $source -}}
{{- else -}}
{{- with $404image := resources.Get "data/media/404.png" -}}
- {{- $width = $404image.Width -}}
+ {{- $width = $404image.Width -}}
{{- $height = $404image.Height -}}
{{- $source = $404image.Permalink -}}
{{- end -}}
@@ -49,7 +54,7 @@
{{- $width = $cache.Width -}}
{{- $height = $cache.Height -}}
{{- $colors = $cache.Colors -}}
- {{- $cache = $cache.Permalink -}}
+ {{- $cache = $cache.Permalink -}}
{{- end -}}
{{- end -}}
{{- end -}}
@@ -58,8 +63,14 @@
{{- $width = $cache.Width -}}
{{- $height = $cache.Height -}}
{{- $colors = $cache.Colors -}}
+ {{- $type = $cache.MediaType -}}
{{- $srcset = print ("" | absURL) "/" $storage ".webp" -}}
- {{- $cache = print ("" | absURL) "/" $storage (path.Ext $cache) -}}
+ {{- end -}}
+ {{- range $extension := $fallbacks -}}
+ {{- with resources.Get (print "public/" $storage $extension) -}}
+ {{- $cache = print ("" | absURL) "/" $storage $extension -}}
+ {{- break -}}
+ {{- end -}}
{{- end -}}
{{- end -}}
@@ -67,15 +78,15 @@
{{- $orientation = "portrait" -}}
{{- end -}}
-{{- with $.Title -}}
- {{- $figcaption = . | markdownify -}}
+{{- with $caption := $.Title -}}
+ {{- $figcaption = $caption | markdownify -}}
{{ end }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}
<figure>
<a data-orientation="{{ $orientation }}" href="{{ $source }}">
<picture>
{{- with $srcset }}
- <source srcset="{{ $srcset }}" type="image/webp" />
+ <source srcset="{{ $srcset }}" type="{{ $type }}" />
{{- end }}
<img
loading="lazy"