diff options
author | tdro <tdro@noreply.example.com> | 2022-08-17 04:24:42 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-08-17 04:24:42 -0400 |
commit | 0c354e0988ec4936b42b855d5b4d5e0b19f26a88 (patch) | |
tree | 730d959517d5d0c1b3983668430fd17a01599ddb /themes | |
parent | fb0eafd272a6cee9b8f9e380cd028f4edde18298 (diff) | |
download | canory-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')
-rw-r--r-- | themes/default/layouts/partials/function-caches-images.html | 57 | ||||
-rw-r--r-- | themes/default/layouts/partials/generate-feeds.html | 6 |
2 files changed, 44 insertions, 19 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) -}} diff --git a/themes/default/layouts/partials/generate-feeds.html b/themes/default/layouts/partials/generate-feeds.html index a3cb7dc..7e6c56c 100644 --- a/themes/default/layouts/partials/generate-feeds.html +++ b/themes/default/layouts/partials/generate-feeds.html @@ -200,12 +200,10 @@ {{- $imageSource := partial "function-caches-images.html" (dict - "File" $domain - "Type" "png" "Source" $faviconDomain "Dimensions" "160x160" - "PrefixSource" (print (partial "function-paths.html" "media") "/") - "PrefixCopy" (print (partial "function-paths.html" "media") "/") + "Directory" (print (partial "function-paths.html" "media") "/") + "Copy" (print (partial "function-paths.html" "media") "/favicon." $domain ".png") ) -}} |