aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/partials/function-caches-images.html
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-08-17 04:24:42 -0400
committertdro <tdro@noreply.example.com>2022-08-17 04:24:42 -0400
commit0c354e0988ec4936b42b855d5b4d5e0b19f26a88 (patch)
tree730d959517d5d0c1b3983668430fd17a01599ddb /themes/default/layouts/partials/function-caches-images.html
parentfb0eafd272a6cee9b8f9e380cd028f4edde18298 (diff)
downloadcanory-0c354e0988ec4936b42b855d5b4d5e0b19f26a88.tar.gz
canory-0c354e0988ec4936b42b855d5b4d5e0b19f26a88.tar.bz2
canory-0c354e0988ec4936b42b855d5b4d5e0b19f26a88.zip
themes/default/layouts/partials/function-caches-images: Simplify
Use path base and generate webp format for fallback.
Diffstat (limited to 'themes/default/layouts/partials/function-caches-images.html')
-rw-r--r--themes/default/layouts/partials/function-caches-images.html57
1 files changed, 42 insertions, 15 deletions
diff --git a/themes/default/layouts/partials/function-caches-images.html b/themes/default/layouts/partials/function-caches-images.html
index b0428e2..145f5e3 100644
--- a/themes/default/layouts/partials/function-caches-images.html
+++ b/themes/default/layouts/partials/function-caches-images.html
@@ -1,30 +1,57 @@
-{{- $source := .Source -}}
-{{- $file := .File -}}
-{{- $404image := resources.Get "data/media/404.png" -}}
-{{- $data := $404image.RelPermalink -}}
-{{- $type := or .Type "png" -}}
-{{- $dimensions := or .Dimensions "300x300" -}}
-{{- $prefixSource := or .PrefixSource "/" -}}
-{{- $prefixCopy := or .PrefixCopy "/" -}}
-{{- $copy := print $prefixCopy "favicon." $file "." $type -}}
-{{- $cached := fileExists (print "public/" $copy) -}}
+{{- $data := slice -}}
+{{- $source := .Source -}}
+{{- $dimensions := or .Dimensions "300x300" -}}
+{{- $directory := or .Directory "/" -}}
+{{- $copy := .Copy -}}
+{{- $type := strings.TrimPrefix "." (path.Ext $copy) -}}
+{{- $cached := fileExists (print "public/" $copy) -}}
+
+{{- with $404image := resources.Get "data/media/404.png" -}}
+ {{- $404image = .Content | resources.FromString (print $directory (path.Base .)) -}}
+ {{-
+ $data = $data | append (dict
+ "Width" $404image.Width
+ "Height" $404image.Height
+ "Permalink" $404image.Permalink
+ "RelPermalink" $404image.RelPermalink
+ )
+ -}}
+{{- end -}}
{{- if $cached -}}
{{- with $image := resources.Get (print "public/" $copy) -}}
- {{- $image = .Content | resources.FromString (print $prefixSource ($image | urlize)) -}}
- {{- $data = $image.RelPermalink -}}
+ {{- $image = .Content | resources.FromString (print $directory (path.Base .)) -}}
+ {{-
+ $data = slice | append (dict
+ "Width" $image.Width
+ "Height" $image.Height
+ "Permalink" $image.Permalink
+ "RelPermalink" $image.RelPermalink
+ )
+ -}}
{{- end -}}
{{- else -}}
{{- with $image := resources.GetRemote $source -}}
{{- with .Err -}}
{{- warnf "%s" . -}}
{{- else -}}
- {{- $image = .Content | resources.FromString (print $prefixSource ($image | urlize)) -}}
+ {{- $image = .Content | resources.FromString (print $directory (path.Base .)) -}}
{{- $image = $image.Fit (print $dimensions " " $type) -}}
{{- $image = $image | resources.Copy $copy -}}
- {{- $data = $image.RelPermalink -}}
+ {{-
+ $data = slice | append (dict
+ "Width" $image.Width
+ "Height" $image.Height
+ "Permalink" $image.Permalink
+ "RelPermalink" $image.RelPermalink
+ )
+ -}}
+ {{- $image = .Content | resources.FromString (print $directory (path.Base .)) -}}
+ {{- $image = $image.Fit (print $dimensions " " "webp") -}}
+ {{- $image = $image | resources.Copy (print (path.Dir $copy) "/" (path.BaseName $copy) ".webp") -}}
+ {{- $writeToFile := $image.Permalink -}}
{{- end -}}
{{- end -}}
{{- end -}}
-{{- return $data -}}
+{{- return (index $data 0) -}}