aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-07-18 12:27:23 -0400
committertdro <tdro@noreply.example.com>2022-07-18 12:27:23 -0400
commite5b102711f9afb5ed7eea28d9ef191cbe1b8db05 (patch)
tree4fecaa2f42abc4e21c3ffb5322c58988d5fc55f6
parent004dfef5eb2e81e39cbb11a766b0a22975e48194 (diff)
downloadcanory-e5b102711f9afb5ed7eea28d9ef191cbe1b8db05.tar.gz
canory-e5b102711f9afb5ed7eea28d9ef191cbe1b8db05.tar.bz2
canory-e5b102711f9afb5ed7eea28d9ef191cbe1b8db05.zip
themes/default/layouts/partials/function: Do not fetch saved favicons again
Separate fetch function. Use permalink in write to file pattern.
-rw-r--r--.gitignore1
-rw-r--r--themes/default/layouts/partials/function-feeds-favicons.html21
-rw-r--r--themes/default/layouts/partials/generate-authors.html12
-rw-r--r--themes/default/layouts/partials/generate-feeds.html23
4 files changed, 36 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 4077f0f..c8f7ee5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.hugo_build.lock
icons
public
resources
diff --git a/themes/default/layouts/partials/function-feeds-favicons.html b/themes/default/layouts/partials/function-feeds-favicons.html
new file mode 100644
index 0000000..e2c77c5
--- /dev/null
+++ b/themes/default/layouts/partials/function-feeds-favicons.html
@@ -0,0 +1,21 @@
+{{- $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-authors.html b/themes/default/layouts/partials/generate-authors.html
index 8e2081f..f622765 100644
--- a/themes/default/layouts/partials/generate-authors.html
+++ b/themes/default/layouts/partials/generate-authors.html
@@ -11,7 +11,7 @@
)
$configuration
-}}
- {{- $writeToFile := $configuration.RelPermalink -}}
+ {{- $writeToFile := $configuration.Permalink -}}
{{- end -}}
@@ -25,7 +25,7 @@
)
$markdown
-}}
- {{- $writeToFile := $template.RelPermalink -}}
+ {{- $writeToFile := $template.Permalink -}}
{{- $template := resources.ExecuteAsTemplate
(print "/data/generates/content/" . "/feeds/" "_index.md")
@@ -35,7 +35,7 @@
)
$markdown
-}}
- {{- $writeToFile := $template.RelPermalink -}}
+ {{- $writeToFile := $template.Permalink -}}
{{- $template := resources.ExecuteAsTemplate
(print "/data/generates/content/" . "/media/" "_index.md")
@@ -45,7 +45,7 @@
)
$markdown
-}}
- {{- $writeToFile := $template.RelPermalink -}}
+ {{- $writeToFile := $template.Permalink -}}
{{- $template := resources.ExecuteAsTemplate
(print "/data/generates/content/" . "/likes/" "_index.md")
@@ -55,7 +55,7 @@
)
$markdown
-}}
- {{- $writeToFile := $template.RelPermalink -}}
+ {{- $writeToFile := $template.Permalink -}}
{{- $template := resources.ExecuteAsTemplate
(print "/data/generates/content/" . "/drafts/" "_index.md")
@@ -65,6 +65,6 @@
)
$markdown
-}}
- {{- $writeToFile := $template.RelPermalink -}}
+ {{- $writeToFile := $template.Permalink -}}
{{- end -}}
diff --git a/themes/default/layouts/partials/generate-feeds.html b/themes/default/layouts/partials/generate-feeds.html
index 67c9556..4421ee8 100644
--- a/themes/default/layouts/partials/generate-feeds.html
+++ b/themes/default/layouts/partials/generate-feeds.html
@@ -172,7 +172,7 @@
{{- range $feeds -}}
- {{- $imageCanonicalURL :=
+ {{- $faviconDomain :=
(print
"https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url="
"http://"
@@ -181,19 +181,12 @@
)
-}}
- {{- $404image := resources.Get "data/media/404.png" -}}
- {{- $imageSource := $404image.RelPermalink -}}
- {{- $imageTitle := "No image found" -}}
-
- {{- with $image := resources.GetRemote $imageCanonicalURL -}}
- {{- with .Err -}}
- {{- warnf "%s" . -}}
- {{- else -}}
- {{- $imageContent := $image.Content | resources.FromString (print (partial "function-paths.html" "media") "/" ($image | urlize)) -}}
- {{- $imageSource = $imageContent.RelPermalink -}}
- {{- $imageTitle = $imageCanonicalURL -}}
- {{- end -}}
- {{- end -}}
+ {{- $imageSource := partial "function-feeds-favicons.html"
+ (dict
+ "Domain" .FeedSourceDomain
+ "Search" $faviconDomain
+ )
+ -}}
{{- $template := resources.Get "templates/markdown-feed.yaml" -}}
{{- $name := print (delimit (first 8 (split (.FeedTitle | urlize) "-")) "-" | humanize | urlize) "-" (.FeedLink | sha256 | truncate 8 "") | humanize | urlize -}}
@@ -227,7 +220,7 @@
)
$template
-}}
- {{- $writeToFile := $markdown.RelPermalink -}}
+ {{- $writeToFile := $markdown.Permalink -}}
{{ end }}
<web-ring>