From e5b102711f9afb5ed7eea28d9ef191cbe1b8db05 Mon Sep 17 00:00:00 2001 From: tdro Date: Mon, 18 Jul 2022 12:27:23 -0400 Subject: themes/default/layouts/partials/function: Do not fetch saved favicons again Separate fetch function. Use permalink in write to file pattern. --- .gitignore | 1 + .../layouts/partials/function-feeds-favicons.html | 21 ++++++++++++++++++++ .../default/layouts/partials/generate-authors.html | 12 +++++------ .../default/layouts/partials/generate-feeds.html | 23 ++++++++-------------- 4 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 themes/default/layouts/partials/function-feeds-favicons.html 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 }} -- cgit v1.2.3