From 72f3e6e848f0a965118b0b9cab894bb5b862c29b Mon Sep 17 00:00:00 2001 From: tdro Date: Mon, 6 Nov 2023 20:15:38 -0500 Subject: themes/default/layouts/_default/_markup/render-image: Resolve types --- .../layouts/_default/_markup/render-image.html | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'themes/default/layouts/_default') 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. */ -}}
{{- with $srcset }} - + {{- end }}