From a7c7dbc0dc876617ff107bba9acb286069ec3dd0 Mon Sep 17 00:00:00 2001 From: tdro Date: Thu, 16 Jun 2022 20:31:05 -0400 Subject: themes/default/layouts/partials/feeds-generate -> generate-feeds --- themes/default/layouts/_default/feeds.html | 2 +- .../default/layouts/partials/feeds-generate.html | 282 --------------------- .../default/layouts/partials/generate-feeds.html | 282 +++++++++++++++++++++ themes/default/layouts/partials/web-ring.html | 2 +- 4 files changed, 284 insertions(+), 284 deletions(-) delete mode 100644 themes/default/layouts/partials/feeds-generate.html create mode 100644 themes/default/layouts/partials/generate-feeds.html diff --git a/themes/default/layouts/_default/feeds.html b/themes/default/layouts/_default/feeds.html index fe2fbaf..7122fde 100644 --- a/themes/default/layouts/_default/feeds.html +++ b/themes/default/layouts/_default/feeds.html @@ -37,7 +37,7 @@ {{ partial "pagination.html" . }} - {{ partial "feeds-generate" . }} + {{ partial "generate-feeds" . }} {{ end }} diff --git a/themes/default/layouts/partials/feeds-generate.html b/themes/default/layouts/partials/feeds-generate.html deleted file mode 100644 index c582d02..0000000 --- a/themes/default/layouts/partials/feeds-generate.html +++ /dev/null @@ -1,282 +0,0 @@ -{{- $author := index .Site.Data.authors ((or .Params.author .Site.Author.default.user) | default "default") -}} - -{{- $feeds := slice -}} - -{{- if $author.webring.rss -}} - {{- range $key, $value := (seq 3) -}} - {{- range $author.webring.rss -}} - - {{- with resources.GetRemote . -}} - {{- with .Err -}} - {{- warnf "Feed fetch %s" . -}} - {{- end -}} - {{- end -}} - - {{- with resources.GetRemote . | transform.Unmarshal -}} - - {{- $title := "No Title Found" -}} - {{- $link := "https://example.com/link" -}} - {{- $description := "No description found." -}} - {{- $content := "No content found." -}} - {{- $sourceTitle := "No source title found" -}} - {{- $sourceLink := "https://example.com/" -}} - {{- $sourceDescription := "No source description found." -}} - {{- $date := now.Format "2006-01-02T15:04:05Z" -}} - {{- $enclosure := "" -}} - - {{- with .channel -}} - - {{- $sourceTitle = .title -}} - {{- $sourceDescription = .description -}} - - {{- if reflect.IsSlice .link -}} - {{- if reflect.IsMap (index .link 0) -}} - {{- $sourceLink = index (index .link 0) "-href" -}} - {{- else -}} - {{- $sourceLink = index .link 0 -}} - {{- end -}} - {{- else -}} - {{- $sourceLink = .link -}} - {{- 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 -}} - - {{- /* Common time zone typos. */ -}} - {{- $date = strings.Replace $date "G6T" "GST" -}} - - {{- /* If missing seconds split and try again. */ -}} - {{- if lt (len (split $date ":")) 3 -}} - {{- $date = delimit (first 3 (after 1 (split $date " "))) " " -}} - {{- end -}} - - {{ - $feeds = $feeds | append (dict - "FeedContent" ($content | plainify | htmlUnescape) - "FeedContentShort" (delimit (first 2 (split ($content | plainify | htmlUnescape) "\n")) " " | truncate 250) - "FeedDate" ($date | plainify | htmlUnescape | time.Format "January 2, 2006") - "FeedDateTime" ($date | plainify | htmlUnescape | time.Format "2006-01-02T15:04:05Z") - "FeedDateTitle" ($date | plainify | htmlUnescape | time.Format "Monday, January 2 2006 at 15:04:05 MST") - "FeedDescription" ($description | plainify | htmlUnescape) - "FeedDescriptionShort" (delimit (first 2 (split ($description | plainify | htmlUnescape) "\n")) " " | truncate 250) - "FeedEnclosure" ($enclosure | plainify | htmlUnescape) - "FeedLink" ($link | plainify | htmlUnescape) - "FeedName" (delimit ((delimit (first 2 (split ($sourceTitle | plainify | htmlUnescape) " ")) " ") | findRE "^([^.|?|!|\n|\"|]+)") " " | replaceRE "[^a-zA-Z ]" "") - "FeedSourceDescription" ($sourceDescription | plainify | htmlUnescape) - "FeedSourceDomain" (($sourceLink | plainify | htmlUnescape | urls.Parse).Host) - "FeedSourceLink" ($sourceLink | plainify | htmlUnescape) - "FeedSourceTitle" ($sourceTitle | plainify | htmlUnescape) - "FeedTitle" ($title | plainify | htmlUnescape) - ) - -}} - - {{- end -}} - {{- end -}} - {{- end -}} - - {{- range $feeds -}} - - {{- $imageCanonicalURL := - (print - "https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=" - "http://" - .FeedSourceDomain - "&size=64" - ) - -}} - - {{- $imageSource := "/images/404.png" -}} - {{- $imageTitle := "No image found" -}} - - {{- with $image := resources.GetRemote $imageCanonicalURL -}} - {{- with .Err -}} - {{- warnf "%s" . -}} - {{- $fallbackImage := imageConfig (print "static/images/404.png") -}} - {{- with $fallbackImage -}} - {{- $fallbackWidth := .Width -}} - {{- $fallbackHeight := .Height -}} - {{- end -}} - {{- else -}} - {{- $imageContent := $image.Content | resources.FromString (print "/data/static/images/" ($image | urlize)) -}} - {{- $imageSource = $imageContent.RelPermalink -}} - {{- $imageTitle = $imageCanonicalURL -}} - {{- end -}} - {{- end -}} - - {{- $template := resources.Get "templates/markdown-feed.yaml" -}} - {{- $name := print (delimit (first 8 (split (.FeedTitle | urlize) "-")) "-" | humanize | urlize) "-" (.FeedLink | sha256 | truncate 8 "") | humanize | urlize -}} - {{- $path := print "/data/generates/content/" $author.user "/feeds/" $name ".md" -}} - - {{- $description := .FeedDescriptionShort -}} - {{- if gt (len .FeedTitle) (len .FeedDescriptionShort) -}} - {{- $description = .FeedTitle -}} - {{- end -}} - - {{- $content := .FeedContentShort -}} - {{- if gt (len .FeedTitle) (len .FeedContentShort) -}} - {{- $content = .FeedTitle -}} - {{- end -}} - - {{- $link := .FeedLink -}} - {{- $enclosure := .FeedEnclosure -}} - {{- if or - (in .FeedLink ".apng") - (in .FeedLink ".avif") - (in .FeedLink ".gif") - (in .FeedLink ".jfif") - (in .FeedLink ".jpeg") - (in .FeedLink ".jpg") - (in .FeedLink ".pjp") - (in .FeedLink ".pjpeg") - (in .FeedLink ".png") - (in .FeedLink ".svg") - (in .FeedLink ".webp") - -}} - {{- if (.Feedlink | urls.Parse).Host -}} - {{- else -}} - {{- $enclosure = print "http://" .FeedSourceDomain .FeedLink -}} - {{- $link = $enclosure -}} - {{- end -}} - {{- end -}} - - {{- $markdown := resources.ExecuteAsTemplate - $path - (dict - "author" $author.user - "content" $content - "date" .FeedDateTime - "description" .FeedSourceTitle - "domain" .FeedSourceDomain - "enclosure" $enclosure - "image" $imageSource - "link" $link - "name" .FeedName - "raw" (strings.TrimLeft "/" $path) - "self" (print $author.user "/feeds/" $name "/") - "tags" "[rss]" - ) - $template - -}} - {{- $writeToFile := $markdown.RelPermalink -}} - {{ end }} - - -

Web Ring

- -
-{{- end -}} diff --git a/themes/default/layouts/partials/generate-feeds.html b/themes/default/layouts/partials/generate-feeds.html new file mode 100644 index 0000000..c582d02 --- /dev/null +++ b/themes/default/layouts/partials/generate-feeds.html @@ -0,0 +1,282 @@ +{{- $author := index .Site.Data.authors ((or .Params.author .Site.Author.default.user) | default "default") -}} + +{{- $feeds := slice -}} + +{{- if $author.webring.rss -}} + {{- range $key, $value := (seq 3) -}} + {{- range $author.webring.rss -}} + + {{- with resources.GetRemote . -}} + {{- with .Err -}} + {{- warnf "Feed fetch %s" . -}} + {{- end -}} + {{- end -}} + + {{- with resources.GetRemote . | transform.Unmarshal -}} + + {{- $title := "No Title Found" -}} + {{- $link := "https://example.com/link" -}} + {{- $description := "No description found." -}} + {{- $content := "No content found." -}} + {{- $sourceTitle := "No source title found" -}} + {{- $sourceLink := "https://example.com/" -}} + {{- $sourceDescription := "No source description found." -}} + {{- $date := now.Format "2006-01-02T15:04:05Z" -}} + {{- $enclosure := "" -}} + + {{- with .channel -}} + + {{- $sourceTitle = .title -}} + {{- $sourceDescription = .description -}} + + {{- if reflect.IsSlice .link -}} + {{- if reflect.IsMap (index .link 0) -}} + {{- $sourceLink = index (index .link 0) "-href" -}} + {{- else -}} + {{- $sourceLink = index .link 0 -}} + {{- end -}} + {{- else -}} + {{- $sourceLink = .link -}} + {{- 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 -}} + + {{- /* Common time zone typos. */ -}} + {{- $date = strings.Replace $date "G6T" "GST" -}} + + {{- /* If missing seconds split and try again. */ -}} + {{- if lt (len (split $date ":")) 3 -}} + {{- $date = delimit (first 3 (after 1 (split $date " "))) " " -}} + {{- end -}} + + {{ + $feeds = $feeds | append (dict + "FeedContent" ($content | plainify | htmlUnescape) + "FeedContentShort" (delimit (first 2 (split ($content | plainify | htmlUnescape) "\n")) " " | truncate 250) + "FeedDate" ($date | plainify | htmlUnescape | time.Format "January 2, 2006") + "FeedDateTime" ($date | plainify | htmlUnescape | time.Format "2006-01-02T15:04:05Z") + "FeedDateTitle" ($date | plainify | htmlUnescape | time.Format "Monday, January 2 2006 at 15:04:05 MST") + "FeedDescription" ($description | plainify | htmlUnescape) + "FeedDescriptionShort" (delimit (first 2 (split ($description | plainify | htmlUnescape) "\n")) " " | truncate 250) + "FeedEnclosure" ($enclosure | plainify | htmlUnescape) + "FeedLink" ($link | plainify | htmlUnescape) + "FeedName" (delimit ((delimit (first 2 (split ($sourceTitle | plainify | htmlUnescape) " ")) " ") | findRE "^([^.|?|!|\n|\"|]+)") " " | replaceRE "[^a-zA-Z ]" "") + "FeedSourceDescription" ($sourceDescription | plainify | htmlUnescape) + "FeedSourceDomain" (($sourceLink | plainify | htmlUnescape | urls.Parse).Host) + "FeedSourceLink" ($sourceLink | plainify | htmlUnescape) + "FeedSourceTitle" ($sourceTitle | plainify | htmlUnescape) + "FeedTitle" ($title | plainify | htmlUnescape) + ) + -}} + + {{- end -}} + {{- end -}} + {{- end -}} + + {{- range $feeds -}} + + {{- $imageCanonicalURL := + (print + "https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=" + "http://" + .FeedSourceDomain + "&size=64" + ) + -}} + + {{- $imageSource := "/images/404.png" -}} + {{- $imageTitle := "No image found" -}} + + {{- with $image := resources.GetRemote $imageCanonicalURL -}} + {{- with .Err -}} + {{- warnf "%s" . -}} + {{- $fallbackImage := imageConfig (print "static/images/404.png") -}} + {{- with $fallbackImage -}} + {{- $fallbackWidth := .Width -}} + {{- $fallbackHeight := .Height -}} + {{- end -}} + {{- else -}} + {{- $imageContent := $image.Content | resources.FromString (print "/data/static/images/" ($image | urlize)) -}} + {{- $imageSource = $imageContent.RelPermalink -}} + {{- $imageTitle = $imageCanonicalURL -}} + {{- end -}} + {{- end -}} + + {{- $template := resources.Get "templates/markdown-feed.yaml" -}} + {{- $name := print (delimit (first 8 (split (.FeedTitle | urlize) "-")) "-" | humanize | urlize) "-" (.FeedLink | sha256 | truncate 8 "") | humanize | urlize -}} + {{- $path := print "/data/generates/content/" $author.user "/feeds/" $name ".md" -}} + + {{- $description := .FeedDescriptionShort -}} + {{- if gt (len .FeedTitle) (len .FeedDescriptionShort) -}} + {{- $description = .FeedTitle -}} + {{- end -}} + + {{- $content := .FeedContentShort -}} + {{- if gt (len .FeedTitle) (len .FeedContentShort) -}} + {{- $content = .FeedTitle -}} + {{- end -}} + + {{- $link := .FeedLink -}} + {{- $enclosure := .FeedEnclosure -}} + {{- if or + (in .FeedLink ".apng") + (in .FeedLink ".avif") + (in .FeedLink ".gif") + (in .FeedLink ".jfif") + (in .FeedLink ".jpeg") + (in .FeedLink ".jpg") + (in .FeedLink ".pjp") + (in .FeedLink ".pjpeg") + (in .FeedLink ".png") + (in .FeedLink ".svg") + (in .FeedLink ".webp") + -}} + {{- if (.Feedlink | urls.Parse).Host -}} + {{- else -}} + {{- $enclosure = print "http://" .FeedSourceDomain .FeedLink -}} + {{- $link = $enclosure -}} + {{- end -}} + {{- end -}} + + {{- $markdown := resources.ExecuteAsTemplate + $path + (dict + "author" $author.user + "content" $content + "date" .FeedDateTime + "description" .FeedSourceTitle + "domain" .FeedSourceDomain + "enclosure" $enclosure + "image" $imageSource + "link" $link + "name" .FeedName + "raw" (strings.TrimLeft "/" $path) + "self" (print $author.user "/feeds/" $name "/") + "tags" "[rss]" + ) + $template + -}} + {{- $writeToFile := $markdown.RelPermalink -}} + {{ end }} + + +

Web Ring

+ +
+{{- end -}} diff --git a/themes/default/layouts/partials/web-ring.html b/themes/default/layouts/partials/web-ring.html index 1f89616..c3d73b4 100644 --- a/themes/default/layouts/partials/web-ring.html +++ b/themes/default/layouts/partials/web-ring.html @@ -1 +1 @@ -{{ partial "feeds-generate" . }} +{{ partial "generate-feeds" . }} -- cgit v1.2.3