aboutsummaryrefslogtreecommitdiff
path: root/themes
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
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')
-rw-r--r--themes/default/layouts/partials/function-caches-images.html30
-rw-r--r--themes/default/layouts/partials/function-feeds-favicons.html21
-rw-r--r--themes/default/layouts/partials/generate-feeds.html10
3 files changed, 37 insertions, 24 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 -}}
diff --git a/themes/default/layouts/partials/function-feeds-favicons.html b/themes/default/layouts/partials/function-feeds-favicons.html
deleted file mode 100644
index e2c77c5..0000000
--- a/themes/default/layouts/partials/function-feeds-favicons.html
+++ /dev/null
@@ -1,21 +0,0 @@
-{{- $search := .Search -}}
-{{- $domain := .Domain -}}
-{{- $404image := resources.Get "data/media/404.png" -}}
-{{- $source := $404image.RelPermalink -}}
-{{- $cachedPath := (print "/" (partial "function-paths.html" "media") "/" "favicon." $domain ".png") -}}
-
-{{- if fileExists (print "public/" $cachedPath) -}}
- {{- $source = $cachedPath -}}
-{{- else -}}
- {{- with $image := resources.GetRemote $search -}}
- {{- with .Err -}}
- {{- warnf "%s" . -}}
- {{- else -}}
- {{- $image = $image.Content | resources.FromString (print (partial "function-paths.html" "media") "/" ($image | urlize)) -}}
- {{- $image = $image | resources.Copy (print (partial "function-paths.html" "media") "/" "favicon." $domain ".png") -}}
- {{- $source = $image.RelPermalink -}}
- {{- end -}}
- {{- end -}}
-{{- end -}}
-
-{{- return $source -}}
diff --git a/themes/default/layouts/partials/generate-feeds.html b/themes/default/layouts/partials/generate-feeds.html
index b8e7f75..a3cb7dc 100644
--- a/themes/default/layouts/partials/generate-feeds.html
+++ b/themes/default/layouts/partials/generate-feeds.html
@@ -198,10 +198,14 @@
{{- $domain = $name | humanize | urlize -}}
{{- end -}}
- {{- $imageSource := partial "function-feeds-favicons.html"
+ {{- $imageSource := partial "function-caches-images.html"
(dict
- "Domain" $domain
- "Search" $faviconDomain
+ "File" $domain
+ "Type" "png"
+ "Source" $faviconDomain
+ "Dimensions" "160x160"
+ "PrefixSource" (print (partial "function-paths.html" "media") "/")
+ "PrefixCopy" (print (partial "function-paths.html" "media") "/")
)
-}}