diff options
author | tdro <tdro@noreply.example.com> | 2022-08-24 01:05:07 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-08-24 01:05:07 -0400 |
commit | d52a19afc98007532a83b2cb4ab577bd14807b13 (patch) | |
tree | e980b83205e4401c6ad3206e27876c42d24ee5df /themes | |
parent | 335ba023b74cac656ef6465cc72bcae0370a4cc4 (diff) | |
download | canory-d52a19afc98007532a83b2cb4ab577bd14807b13.tar.gz canory-d52a19afc98007532a83b2cb4ab577bd14807b13.tar.bz2 canory-d52a19afc98007532a83b2cb4ab577bd14807b13.zip |
themes/default/layouts/partials/function-caches-images: Check for local images
Diffstat (limited to 'themes')
-rw-r--r-- | themes/default/layouts/partials/function-caches-images.html | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/themes/default/layouts/partials/function-caches-images.html b/themes/default/layouts/partials/function-caches-images.html index c8d094d..9a18f7b 100644 --- a/themes/default/layouts/partials/function-caches-images.html +++ b/themes/default/layouts/partials/function-caches-images.html @@ -8,6 +8,8 @@ {{- $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 -}} {{- with $404image := resources.Get "data/media/404.png" -}} {{- $404image = .Content | resources.FromString (print $target (path.Base .)) -}} @@ -36,7 +38,28 @@ {{- else -}} {{- with $image := resources.GetRemote $source -}} {{- with .Err -}} - {{- warnf "%s" . -}} + {{- if $localized -}} + {{- $directory := path.Dir $local -}} + {{- $basename := path.BaseName $local -}} + {{- $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 | resources.Copy $copy -}} + {{- + $data = slice | append (dict + "Width" $image.Width + "Height" $image.Height + "Permalink" $image.Permalink + "RelPermalink" $image.RelPermalink + ) + -}} + {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} + {{- $image = $image.Fit (print $dimensions " " "webp") -}} + {{- $image = $image | resources.Copy $optimized -}} + {{- $writeToFile := $image.Permalink -}} + {{- end -}} + {{- end -}} {{- else -}} {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} {{- $image = $image.Fit (print $dimensions " " $type) -}} |