aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/partials/function-caches-images.html
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-08-15 22:05:35 -0400
committertdro <tdro@noreply.example.com>2022-08-15 22:05:35 -0400
commit93624424bf16c2b97e98f8a5c5483d55f0a5023b (patch)
tree3b64e6afb0d9570d9b82455fa3218e91ef40099a /themes/default/layouts/partials/function-caches-images.html
parent8595c1325bd68fd0c17334c78b85b0fde55986d4 (diff)
downloadcanory-93624424bf16c2b97e98f8a5c5483d55f0a5023b.tar.gz
canory-93624424bf16c2b97e98f8a5c5483d55f0a5023b.tar.bz2
canory-93624424bf16c2b97e98f8a5c5483d55f0a5023b.zip
themes/default/layouts/partials/function: Start unified image caching interface
Diffstat (limited to 'themes/default/layouts/partials/function-caches-images.html')
-rw-r--r--themes/default/layouts/partials/function-caches-images.html30
1 files changed, 30 insertions, 0 deletions
diff --git a/themes/default/layouts/partials/function-caches-images.html b/themes/default/layouts/partials/function-caches-images.html
new file mode 100644
index 0000000..b0428e2
--- /dev/null
+++ b/themes/default/layouts/partials/function-caches-images.html
@@ -0,0 +1,30 @@
+{{- $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) -}}
+
+{{- if $cached -}}
+ {{- with $image := resources.Get (print "public/" $copy) -}}
+ {{- $image = .Content | resources.FromString (print $prefixSource ($image | urlize)) -}}
+ {{- $data = $image.RelPermalink -}}
+ {{- end -}}
+{{- else -}}
+ {{- with $image := resources.GetRemote $source -}}
+ {{- with .Err -}}
+ {{- warnf "%s" . -}}
+ {{- else -}}
+ {{- $image = .Content | resources.FromString (print $prefixSource ($image | urlize)) -}}
+ {{- $image = $image.Fit (print $dimensions " " $type) -}}
+ {{- $image = $image | resources.Copy $copy -}}
+ {{- $data = $image.RelPermalink -}}
+ {{- end -}}
+ {{- end -}}
+{{- end -}}
+
+{{- return $data -}}