aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/partials/function-caches-images.html
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-08-21 23:59:07 -0400
committertdro <tdro@noreply.example.com>2022-08-21 23:59:07 -0400
commit335ba023b74cac656ef6465cc72bcae0370a4cc4 (patch)
treee4f3e5ea31628f8fa1fe9b98b6b0a97fd5f577e1 /themes/default/layouts/partials/function-caches-images.html
parentd4c6aa99b7352100af2c9340aa0e26818e535320 (diff)
downloadcanory-335ba023b74cac656ef6465cc72bcae0370a4cc4.tar.gz
canory-335ba023b74cac656ef6465cc72bcae0370a4cc4.tar.bz2
canory-335ba023b74cac656ef6465cc72bcae0370a4cc4.zip
themes/default/layouts/partials/function-caches-images: Check for optimized
Set up for local targets..
Diffstat (limited to 'themes/default/layouts/partials/function-caches-images.html')
-rw-r--r--themes/default/layouts/partials/function-caches-images.html17
1 files changed, 10 insertions, 7 deletions
diff --git a/themes/default/layouts/partials/function-caches-images.html b/themes/default/layouts/partials/function-caches-images.html
index 145f5e3..c8d094d 100644
--- a/themes/default/layouts/partials/function-caches-images.html
+++ b/themes/default/layouts/partials/function-caches-images.html
@@ -1,13 +1,16 @@
{{- $data := slice -}}
{{- $source := .Source -}}
{{- $dimensions := or .Dimensions "300x300" -}}
-{{- $directory := or .Directory "/" -}}
+{{- $target := or .Target "/" -}}
{{- $copy := .Copy -}}
+{{- $directory := path.Dir $copy -}}
+{{- $basename := path.BaseName $copy -}}
{{- $type := strings.TrimPrefix "." (path.Ext $copy) -}}
-{{- $cached := fileExists (print "public/" $copy) -}}
+{{- $optimized := print $directory "/" $basename ".webp" -}}
+{{- $cached := and (fileExists (print "public/" $copy)) (fileExists (print "public/" $optimized)) -}}
{{- with $404image := resources.Get "data/media/404.png" -}}
- {{- $404image = .Content | resources.FromString (print $directory (path.Base .)) -}}
+ {{- $404image = .Content | resources.FromString (print $target (path.Base .)) -}}
{{-
$data = $data | append (dict
"Width" $404image.Width
@@ -20,7 +23,7 @@
{{- if $cached -}}
{{- with $image := resources.Get (print "public/" $copy) -}}
- {{- $image = .Content | resources.FromString (print $directory (path.Base .)) -}}
+ {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
{{-
$data = slice | append (dict
"Width" $image.Width
@@ -35,7 +38,7 @@
{{- with .Err -}}
{{- warnf "%s" . -}}
{{- else -}}
- {{- $image = .Content | resources.FromString (print $directory (path.Base .)) -}}
+ {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
{{- $image = $image.Fit (print $dimensions " " $type) -}}
{{- $image = $image | resources.Copy $copy -}}
{{-
@@ -46,9 +49,9 @@
"RelPermalink" $image.RelPermalink
)
-}}
- {{- $image = .Content | resources.FromString (print $directory (path.Base .)) -}}
+ {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}}
{{- $image = $image.Fit (print $dimensions " " "webp") -}}
- {{- $image = $image | resources.Copy (print (path.Dir $copy) "/" (path.BaseName $copy) ".webp") -}}
+ {{- $image = $image | resources.Copy $optimized -}}
{{- $writeToFile := $image.Permalink -}}
{{- end -}}
{{- end -}}