From f804191de73059f7112764af0b8c625d06fec61a Mon Sep 17 00:00:00 2001 From: tdro Date: Thu, 20 Oct 2022 22:05:41 -0400 Subject: themes/default/layouts/partials/web-ring: Avoid extra markup with feed function return --- assets/css/default.css | 4 - themes/default/layouts/_default/feeds.html | 2 +- .../layouts/partials/function-generate-feeds.html | 248 ++++++++++++++++++ .../default/layouts/partials/generate-feeds.html | 282 --------------------- themes/default/layouts/partials/web-ring.html | 38 ++- 5 files changed, 286 insertions(+), 288 deletions(-) create mode 100644 themes/default/layouts/partials/function-generate-feeds.html delete mode 100644 themes/default/layouts/partials/generate-feeds.html diff --git a/assets/css/default.css b/assets/css/default.css index 3f5ca32..d51613e 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -1484,10 +1484,6 @@ gallery-overlay { border-color: var(--border-darker); } -main web-ring { - display: none; -} - web-ring { border-radius: 1rem; position: sticky; diff --git a/themes/default/layouts/_default/feeds.html b/themes/default/layouts/_default/feeds.html index 71e6328..2845ea0 100644 --- a/themes/default/layouts/_default/feeds.html +++ b/themes/default/layouts/_default/feeds.html @@ -41,7 +41,7 @@ {{ partial "pagination.html" . }} - {{ partial "generate-feeds" . }} + {{ $writeToFile := partial "function-generate-feeds" . }} {{ end }} diff --git a/themes/default/layouts/partials/function-generate-feeds.html b/themes/default/layouts/partials/function-generate-feeds.html new file mode 100644 index 0000000..e494596 --- /dev/null +++ b/themes/default/layouts/partials/function-generate-feeds.html @@ -0,0 +1,248 @@ +{{- $author := partial "function-authors-data.html" . -}} + +{{- $feeds := slice -}} + +{{- if $author.feeds.rss -}} + {{- range $key, $value := (seq 3) -}} + {{- range $author.feeds.rss -}} + + {{- with resources.GetRemote . -}} + {{- with .Err -}} + {{- warnf "Feed fetch %s" . -}} + {{- end -}} + {{- end -}} + + {{- with resources.GetRemote . | transform.Unmarshal -}} + + {{- $content := "" -}} + {{- $date := now.Format "2006-01-02T15:04:05Z" -}} + {{- $description := "No description found." -}} + {{- $enclosure := "" -}} + {{- $imageLink := "" -}} + {{- $link := "https://example.com/link/" -}} + {{- $sourceDescription := "" -}} + {{- $sourceHome := "" -}} + {{- $sourceLink := "https://example.com/rss/" -}} + {{- $sourceTitle := "No source title found" -}} + {{- $title := "No Title Found" -}} + + {{- with .channel -}} + + {{- $sourceTitle = .title -}} + {{- $sourceDescription = .description -}} + + {{- if reflect.IsSlice .link -}} + {{- if reflect.IsMap (index .link 0) -}} + {{- $sourceLink = index (first 1 .link) 0 "-href" -}} + {{- $sourceHome = index (last 1 .link) 0 -}} + {{- else -}} + {{- $sourceLink = index .link 0 -}} + {{- end -}} + {{- else -}} + {{- $sourceLink = .link -}} + {{- end -}} + + {{- with .image -}} + {{- $imageLink = .url -}} + {{- end -}} + + {{- with .item -}} + {{- if reflect.IsMap . -}} + {{- $title = index . "title" -}} + {{- $link = index . "link" -}} + {{- $date = index . "pubDate" -}} + {{- else -}} + {{- range first $value . -}} + {{- $description = .description -}} + {{- $content = .description -}} + {{- $title = .title -}} + {{- $link = .link -}} + {{- $date = .pubDate -}} + {{- with .enclosure -}} + {{- $enclosure = index . "-url" -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- if not $date -}} + {{- $date = .lastBuildDate -}} + {{- end -}} + + {{- else -}} + + {{- with .link -}} + {{- $sourceLink = index (index . 0) "-href" -}} + {{- end -}} + + {{- with .subtitle -}} + {{- if reflect.IsMap . -}} + {{- $sourceDescription = index . "#text" -}} + {{- else -}} + {{- $sourceDescription = . -}} + {{- end -}} + {{- end -}} + + {{- with .title -}} + {{- if reflect.IsMap . -}} + {{- $sourceTitle = index . "#text" -}} + {{- else -}} + {{- $sourceTitle = . -}} + {{- end -}} + {{- end -}} + + {{- with .entry -}} + {{- range first $value . -}} + {{- $date = .updated -}} + + {{- with .link -}} + {{- if reflect.IsMap . -}} + {{- $link = index . "-href" -}} + {{- else -}} + {{- if reflect.IsMap (index . 0) -}} + {{- $link = index (index . 0) "-href" -}} + {{- else -}} + {{- $link = . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- with .title -}} + {{- if reflect.IsMap . -}} + {{- $title = index . "#text" -}} + {{- else -}} + {{- $title = . -}} + {{- end -}} + {{- end -}} + + {{- with .content -}} + {{- $content = index . "#text" -}} + {{- end -}} + + {{- with .summary -}} + {{- $description = index . "#text" -}} + {{- end -}} + + {{- with .group -}} + {{- $description = .description -}} + {{- $content = index .content "#text" -}} + {{- $enclosure = index .thumbnail "-url" -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- end -}} + + {{- $sourceDomain := ($sourceLink | plainify | html | htmlUnescape | urls.Parse).Host -}} + + {{- /* Replace invalid time zones. */ -}} + {{- $date = replaceRE "G[0-9]+T" "UTC" $date -}} + + {{- /* If missing seconds split and try again. */ -}} + {{- if lt (len (split $date ":")) 3 -}} + {{- $date = delimit (first 3 (after 1 (split $date " "))) " " -}} + {{- end -}} + + {{- /* Try to complete enclosure relative links. */ -}} + {{- if and (not ($enclosure | urls.Parse).Host) (not ($link | urls.Parse).Host) -}} + {{- $enclosure = print "http://" $sourceDomain $link -}} + {{- end -}} + + {{- /* Try to complete link relative links. */ -}} + {{- if not ($link | urls.Parse).Host -}} + {{- $link = print "http://" $sourceDomain $link -}} + {{- end -}} + + {{- + $feeds = $feeds | append (dict + "FeedContent" ($content | plainify | html | htmlUnescape) + "FeedContentShort" (delimit (first 2 (split ($content | plainify | html | htmlUnescape) "\n")) " " | truncate 250) + "FeedDate" ($date | plainify | html | htmlUnescape | time.Format "January 2, 2006") + "FeedDateTime" ($date | plainify | html | htmlUnescape | time.Format "2006-01-02T15:04:05Z") + "FeedDateTitle" ($date | plainify | html | htmlUnescape | time.Format "Monday, January 2 2006 at 15:04:05 MST") + "FeedDescription" ($description | plainify | html | htmlUnescape) + "FeedDescriptionShort" (delimit (first 2 (split ($description | plainify | html | htmlUnescape) "\n")) " " | truncate 250) + "FeedEnclosure" ($enclosure | plainify | html | htmlUnescape) + "FeedImageLink" ($imageLink | plainify | html | htmlUnescape) + "FeedLink" ($link | plainify | html | htmlUnescape) + "FeedName" (delimit ((delimit (first 2 (split ($sourceTitle | plainify | html | htmlUnescape) " ")) " ") | findRE "^([^.|?|!|\n|\"|]+)") " " | replaceRE "[^a-zA-Z ]" "") + "FeedSourceDescription" ($sourceDescription | plainify | html | htmlUnescape) + "FeedSourceDomain" ($sourceDomain | plainify | html | htmlUnescape) + "FeedSourceLink" ($sourceLink | plainify | html | htmlUnescape) + "FeedSourceHome" ($sourceHome | plainify | html | htmlUnescape) + "FeedSourceTitle" ($sourceTitle | plainify | html | htmlUnescape) + "FeedTitle" ($title | plainify | html | htmlUnescape) + ) + -}} + + {{- end -}} + {{- end -}} + {{- end -}} + + {{- range $feeds -}} + + {{- $name := .FeedName -}} + {{- $domain := .FeedSourceDomain -}} + + {{- $faviconDomain := + (print + "https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=" + "http://" + .FeedSourceDomain + "&size=64" + ) + -}} + + {{- with .FeedImageLink -}} + {{- $faviconDomain = . -}} + {{- $domain = $name | humanize | urlize -}} + {{- end -}} + + {{- $imageSource := partial "function-caches-images.html" + (dict + "Source" $faviconDomain + "Fit" "160x160" + "Target" (print (partial "function-paths.html" "media") "/") + "Copy" (print (partial "function-paths.html" "media") "/favicon." $domain ".png") + ) + -}} + + {{- $template := resources.Get "templates/markdown-feed.yaml" -}} + {{- $file := print (delimit (first 8 (split (.FeedTitle | urlize) "-")) "-" | humanize | urlize) "-" (.FeedLink | sha256 | truncate 8 "") -}} + {{- $file = partial "function-strip-urlchars.html" $file -}} + {{- $path := print "/data/generates/content/" $author.user "/feeds/" $file ".md" -}} + + {{- $content := .FeedContentShort -}} + + {{- if (gt (len .FeedTitle) (len $content)) -}} + {{- $content = .FeedTitle -}} + {{- end -}} + + {{- if (gt (len .FeedDescriptionShort) (len .FeedTitle)) -}} + {{- $content = .FeedDescriptionShort -}} + {{- end -}} + + {{- $markdown := resources.ExecuteAsTemplate + $path + (dict + "author" $author.user + "content" (or $content "No content found.") + "date" .FeedDateTime + "description" (or .FeedSourceDescription .FeedSourceTitle "No source description found.") + "domain" .FeedSourceDomain + "enclosure" .FeedEnclosure + "favicon" $imageSource.RelPermalink + "home" .FeedSourceHome + "link" .FeedLink + "markdown" (strings.TrimLeft "/" $path) + "name" .FeedName + "self" (print $author.user "/feeds/" $file "/") + "tags" "[rss]" + ) + $template + -}} + {{- $writeToFile := $markdown.Permalink -}} + {{- end -}} +{{- end -}} + +{{- return $feeds -}} diff --git a/themes/default/layouts/partials/generate-feeds.html b/themes/default/layouts/partials/generate-feeds.html deleted file mode 100644 index a6cd906..0000000 --- a/themes/default/layouts/partials/generate-feeds.html +++ /dev/null @@ -1,282 +0,0 @@ -{{- $author := partial "function-authors-data.html" . -}} - -{{- $feeds := slice -}} - -{{- if $author.feeds.rss -}} - {{- range $key, $value := (seq 3) -}} - {{- range $author.feeds.rss -}} - - {{- with resources.GetRemote . -}} - {{- with .Err -}} - {{- warnf "Feed fetch %s" . -}} - {{- end -}} - {{- end -}} - - {{- with resources.GetRemote . | transform.Unmarshal -}} - - {{- $content := "" -}} - {{- $date := now.Format "2006-01-02T15:04:05Z" -}} - {{- $description := "No description found." -}} - {{- $enclosure := "" -}} - {{- $imageLink := "" -}} - {{- $link := "https://example.com/link/" -}} - {{- $sourceDescription := "" -}} - {{- $sourceHome := "" -}} - {{- $sourceLink := "https://example.com/rss/" -}} - {{- $sourceTitle := "No source title found" -}} - {{- $title := "No Title Found" -}} - - {{- with .channel -}} - - {{- $sourceTitle = .title -}} - {{- $sourceDescription = .description -}} - - {{- if reflect.IsSlice .link -}} - {{- if reflect.IsMap (index .link 0) -}} - {{- $sourceLink = index (first 1 .link) 0 "-href" -}} - {{- $sourceHome = index (last 1 .link) 0 -}} - {{- else -}} - {{- $sourceLink = index .link 0 -}} - {{- end -}} - {{- else -}} - {{- $sourceLink = .link -}} - {{- end -}} - - {{- with .image -}} - {{- $imageLink = .url -}} - {{- end -}} - - {{- with .item -}} - {{- if reflect.IsMap . -}} - {{- $title = index . "title" -}} - {{- $link = index . "link" -}} - {{- $date = index . "pubDate" -}} - {{- else -}} - {{- range first $value . -}} - {{- $description = .description -}} - {{- $content = .description -}} - {{- $title = .title -}} - {{- $link = .link -}} - {{- $date = .pubDate -}} - {{- with .enclosure -}} - {{- $enclosure = index . "-url" -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- end -}} - - {{- if not $date -}} - {{- $date = .lastBuildDate -}} - {{- end -}} - - {{- else -}} - - {{- with .link -}} - {{- $sourceLink = index (index . 0) "-href" -}} - {{- end -}} - - {{- with .subtitle -}} - {{- if reflect.IsMap . -}} - {{- $sourceDescription = index . "#text" -}} - {{- else -}} - {{- $sourceDescription = . -}} - {{- end -}} - {{- end -}} - - {{- with .title -}} - {{- if reflect.IsMap . -}} - {{- $sourceTitle = index . "#text" -}} - {{- else -}} - {{- $sourceTitle = . -}} - {{- end -}} - {{- end -}} - - {{- with .entry -}} - {{- range first $value . -}} - {{- $date = .updated -}} - - {{- with .link -}} - {{- if reflect.IsMap . -}} - {{- $link = index . "-href" -}} - {{- else -}} - {{- if reflect.IsMap (index . 0) -}} - {{- $link = index (index . 0) "-href" -}} - {{- else -}} - {{- $link = . -}} - {{- end -}} - {{- end -}} - {{- end -}} - - {{- with .title -}} - {{- if reflect.IsMap . -}} - {{- $title = index . "#text" -}} - {{- else -}} - {{- $title = . -}} - {{- end -}} - {{- end -}} - - {{- with .content -}} - {{- $content = index . "#text" -}} - {{- end -}} - - {{- with .summary -}} - {{- $description = index . "#text" -}} - {{- end -}} - - {{- with .group -}} - {{- $description = .description -}} - {{- $content = index .content "#text" -}} - {{- $enclosure = index .thumbnail "-url" -}} - {{- end -}} - {{- end -}} - {{- end -}} - - {{- end -}} - - {{- $sourceDomain := ($sourceLink | plainify | html | htmlUnescape | urls.Parse).Host -}} - - {{- /* Replace invalid time zones. */ -}} - {{- $date = replaceRE "G[0-9]+T" "UTC" $date -}} - - {{- /* If missing seconds split and try again. */ -}} - {{- if lt (len (split $date ":")) 3 -}} - {{- $date = delimit (first 3 (after 1 (split $date " "))) " " -}} - {{- end -}} - - {{- /* Try to complete enclosure relative links. */ -}} - {{- if and (not ($enclosure | urls.Parse).Host) (not ($link | urls.Parse).Host) -}} - {{- $enclosure = print "http://" $sourceDomain $link -}} - {{- end -}} - - {{- /* Try to complete link relative links. */ -}} - {{- if not ($link | urls.Parse).Host -}} - {{- $link = print "http://" $sourceDomain $link -}} - {{- end -}} - - {{- - $feeds = $feeds | append (dict - "FeedContent" ($content | plainify | html | htmlUnescape) - "FeedContentShort" (delimit (first 2 (split ($content | plainify | html | htmlUnescape) "\n")) " " | truncate 250) - "FeedDate" ($date | plainify | html | htmlUnescape | time.Format "January 2, 2006") - "FeedDateTime" ($date | plainify | html | htmlUnescape | time.Format "2006-01-02T15:04:05Z") - "FeedDateTitle" ($date | plainify | html | htmlUnescape | time.Format "Monday, January 2 2006 at 15:04:05 MST") - "FeedDescription" ($description | plainify | html | htmlUnescape) - "FeedDescriptionShort" (delimit (first 2 (split ($description | plainify | html | htmlUnescape) "\n")) " " | truncate 250) - "FeedEnclosure" ($enclosure | plainify | html | htmlUnescape) - "FeedImageLink" ($imageLink | plainify | html | htmlUnescape) - "FeedLink" ($link | plainify | html | htmlUnescape) - "FeedName" (delimit ((delimit (first 2 (split ($sourceTitle | plainify | html | htmlUnescape) " ")) " ") | findRE "^([^.|?|!|\n|\"|]+)") " " | replaceRE "[^a-zA-Z ]" "") - "FeedSourceDescription" ($sourceDescription | plainify | html | htmlUnescape) - "FeedSourceDomain" ($sourceDomain | plainify | html | htmlUnescape) - "FeedSourceLink" ($sourceLink | plainify | html | htmlUnescape) - "FeedSourceHome" ($sourceHome | plainify | html | htmlUnescape) - "FeedSourceTitle" ($sourceTitle | plainify | html | htmlUnescape) - "FeedTitle" ($title | plainify | html | htmlUnescape) - ) - -}} - - {{- end -}} - {{- end -}} - {{- end -}} - - {{- range $feeds -}} - - {{- $name := .FeedName -}} - {{- $domain := .FeedSourceDomain -}} - - {{- $faviconDomain := - (print - "https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=" - "http://" - .FeedSourceDomain - "&size=64" - ) - -}} - - {{- with .FeedImageLink -}} - {{- $faviconDomain = . -}} - {{- $domain = $name | humanize | urlize -}} - {{- end -}} - - {{- $imageSource := partial "function-caches-images.html" - (dict - "Source" $faviconDomain - "Fit" "160x160" - "Target" (print (partial "function-paths.html" "media") "/") - "Copy" (print (partial "function-paths.html" "media") "/favicon." $domain ".png") - ) - -}} - - {{- $template := resources.Get "templates/markdown-feed.yaml" -}} - {{- $file := print (delimit (first 8 (split (.FeedTitle | urlize) "-")) "-" | humanize | urlize) "-" (.FeedLink | sha256 | truncate 8 "") -}} - {{- $file = partial "function-strip-urlchars.html" $file -}} - {{- $path := print "/data/generates/content/" $author.user "/feeds/" $file ".md" -}} - - {{- $content := .FeedContentShort -}} - - {{- if (gt (len .FeedTitle) (len $content)) -}} - {{- $content = .FeedTitle -}} - {{- end -}} - - {{- if (gt (len .FeedDescriptionShort) (len .FeedTitle)) -}} - {{- $content = .FeedDescriptionShort -}} - {{- end -}} - - {{- $markdown := resources.ExecuteAsTemplate - $path - (dict - "author" $author.user - "content" (or $content "No content found.") - "date" .FeedDateTime - "description" (or .FeedSourceDescription .FeedSourceTitle "No source description found.") - "domain" .FeedSourceDomain - "enclosure" .FeedEnclosure - "favicon" $imageSource.RelPermalink - "home" .FeedSourceHome - "link" .FeedLink - "markdown" (strings.TrimLeft "/" $path) - "name" .FeedName - "self" (print $author.user "/feeds/" $file "/") - "tags" "[rss]" - ) - $template - -}} - {{- $writeToFile := $markdown.Permalink -}} - {{ end }} - - -

Web Ring

- -
-{{- end -}} diff --git a/themes/default/layouts/partials/web-ring.html b/themes/default/layouts/partials/web-ring.html index c3d73b4..8228fbd 100644 --- a/themes/default/layouts/partials/web-ring.html +++ b/themes/default/layouts/partials/web-ring.html @@ -1 +1,37 @@ -{{ partial "generate-feeds" . }} +{{- $feeds := partial "function-generate-feeds.html" . -}} + + +

Web Ring

+ +
-- cgit v1.2.3