aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/partials/function-caches-images.html
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-08-27 01:11:01 -0400
committertdro <tdro@noreply.example.com>2022-08-27 01:11:01 -0400
commitb77c159ae5cfc45e7fd80457e840e769fc97b555 (patch)
tree2b9dd80d69c88c5d9a9530385446f5728c3e7b4e /themes/default/layouts/partials/function-caches-images.html
parent48b4ebde6b2ec65c4e05a8d2118ba04e2f0a3f03 (diff)
downloadcanory-b77c159ae5cfc45e7fd80457e840e769fc97b555.tar.gz
canory-b77c159ae5cfc45e7fd80457e840e769fc97b555.tar.bz2
canory-b77c159ae5cfc45e7fd80457e840e769fc97b555.zip
themes/default/layouts/partials/function-caches-images: Use dictionary and merge
Set up for fit or resize.
Diffstat (limited to 'themes/default/layouts/partials/function-caches-images.html')
-rw-r--r--themes/default/layouts/partials/function-caches-images.html58
1 files changed, 35 insertions, 23 deletions
diff --git a/themes/default/layouts/partials/function-caches-images.html b/themes/default/layouts/partials/function-caches-images.html
index 9a18f7b..d21e72a 100644
--- a/themes/default/layouts/partials/function-caches-images.html
+++ b/themes/default/layouts/partials/function-caches-images.html
@@ -1,20 +1,22 @@
-{{- $data := slice -}}
-{{- $source := .Source -}}
-{{- $dimensions := or .Dimensions "300x300" -}}
-{{- $target := or .Target "/" -}}
-{{- $copy := .Copy -}}
-{{- $directory := path.Dir $copy -}}
-{{- $basename := path.BaseName $copy -}}
-{{- $type := strings.TrimPrefix "." (path.Ext $copy) -}}
-{{- $optimized := print $directory "/" $basename ".webp" -}}
-{{- $cached := and (fileExists (print "public/" $copy)) (fileExists (print "public/" $optimized)) -}}
-{{- $local := print "public/" $source -}}
-{{- $localized := fileExists $local -}}
+{{- $data := dict -}}
+{{- $source := .Source -}}
+{{- $fit := .Fit -}}
+{{- $resize := .Resize -}}
+{{- $target := or .Target "/" -}}
+{{- $copy := .Copy -}}
+{{- $directory := path.Dir $copy -}}
+{{- $basename := path.BaseName $copy -}}
+{{- $type := strings.TrimPrefix "." (path.Ext $copy) -}}
+{{- $optimized := or .OptimizedCopy (print $directory "/" $basename ".webp") -}}
+{{- $optimizedType := strings.TrimPrefix "." (path.Ext $optimized) -}}
+{{- $cached := and (fileExists (print "public/" $copy)) (fileExists (print "public/" $optimized)) -}}
+{{- $local := print "public/" $source -}}
+{{- $localized := fileExists $local -}}
{{- with $404image := resources.Get "data/media/404.png" -}}
{{- $404image = .Content | resources.FromString (print $target (path.Base .)) -}}
{{-
- $data = $data | append (dict
+ $data = (dict
"Width" $404image.Width
"Height" $404image.Height
"Permalink" $404image.Permalink
@@ -27,7 +29,7 @@
{{- with $image := resources.Get (print "public/" $copy) -}}
{{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
{{-
- $data = slice | append (dict
+ $data = (dict
"Width" $image.Width
"Height" $image.Height
"Permalink" $image.Permalink
@@ -44,10 +46,10 @@
{{- $type := strings.TrimPrefix "." (path.Ext $local) -}}
{{- with $image := resources.Get $local -}}
{{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
- {{- $image = $image.Fit (print $dimensions " " $type) -}}
+ {{- $image = $image.Fit (print $fit " " $type) -}}
{{- $image = $image | resources.Copy $copy -}}
{{-
- $data = slice | append (dict
+ $data = (dict
"Width" $image.Width
"Height" $image.Height
"Permalink" $image.Permalink
@@ -55,17 +57,22 @@
)
-}}
{{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
- {{- $image = $image.Fit (print $dimensions " " "webp") -}}
+ {{- $image = $image.Fit (print $fit " " $optimizedType) -}}
{{- $image = $image | resources.Copy $optimized -}}
- {{- $writeToFile := $image.Permalink -}}
+ {{-
+ $data = merge $data (dict
+ "OptPermalink" $image.Permalink
+ "OptRelPermalink" $image.RelPermalink
+ )
+ -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
- {{- $image = $image.Fit (print $dimensions " " $type) -}}
+ {{- $image = $image.Fit (print $fit " " $type) -}}
{{- $image = $image | resources.Copy $copy -}}
{{-
- $data = slice | append (dict
+ $data = (dict
"Width" $image.Width
"Height" $image.Height
"Permalink" $image.Permalink
@@ -73,11 +80,16 @@
)
-}}
{{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
- {{- $image = $image.Fit (print $dimensions " " "webp") -}}
+ {{- $image = $image.Fit (print $fit " " $optimizedType) -}}
{{- $image = $image | resources.Copy $optimized -}}
- {{- $writeToFile := $image.Permalink -}}
+ {{-
+ $data = merge $data (dict
+ "OptPermalink" $image.Permalink
+ "OptRelPermalink" $image.RelPermalink
+ )
+ -}}
{{- end -}}
{{- end -}}
{{- end -}}
-{{- return (index $data 0) -}}
+{{- return $data -}}