From 4c559daf909f025c5e8761e27be6a02fb5f2608f Mon Sep 17 00:00:00 2001 From: tdro Date: Sun, 5 Jun 2022 00:55:53 -0400 Subject: themes/default/layouts/partials/feeds-generate: Naively support enclosures Support showing enclosure images in feeds. The goal is not to be accurate right now. --- assets/templates/markdown-feed.yaml | 22 ++++++++++++ data/authors/canory.yaml | 1 - data/authors/default.yaml | 2 +- .../layouts/_default/_markup/render-image.html | 6 ++-- .../default/layouts/partials/feeds-generate.html | 41 ++++++++++++++++++---- 5 files changed, 61 insertions(+), 11 deletions(-) diff --git a/assets/templates/markdown-feed.yaml b/assets/templates/markdown-feed.yaml index bf883c0..8361144 100644 --- a/assets/templates/markdown-feed.yaml +++ b/assets/templates/markdown-feed.yaml @@ -11,6 +11,7 @@ feed: {{ range $key, $value := . -}} {{- if and + (ne $key "author") (ne $key "content") (ne $key "date") (ne $key "tags") @@ -24,3 +25,24 @@ feed: | replaceRE "{" "{" | replaceRE "}" "}" }} [Read More →]({{ .link }}) + +{{ with .enclosure -}} + +{{- $author := "default" -}} +{{- with $.author -}} + {{ $author = . }} +{{- end -}} + +{{- $description := "Image/Picture" -}} +{{- with $.description -}} + {{ $description = . | htmlEscape }} +{{- end -}} + +{{- with $enclosure := resources.GetRemote . -}} +{{- $enclosure = .Content | resources.FromString (print $author "/media/" ($enclosure | urlize)) -}} +![{{ $description }}]({{ ($enclosure.Resize "600x").RelPermalink }} " + {{ $description }}" +) +{{- end -}} + +{{- end }} diff --git a/data/authors/canory.yaml b/data/authors/canory.yaml index 00ec9cd..7dda4b0 100644 --- a/data/authors/canory.yaml +++ b/data/authors/canory.yaml @@ -15,7 +15,6 @@ description: > webring: rss: - https://deno.com/feed - - https://hacks.mozilla.org/feed/ - https://portable.fyi/feed.xml - https://tomcritchlow.com/feed.xml json: diff --git a/data/authors/default.yaml b/data/authors/default.yaml index 3ab47b6..b73b2b9 100644 --- a/data/authors/default.yaml +++ b/data/authors/default.yaml @@ -14,5 +14,5 @@ description: > webring: rss: - https://hacks.mozilla.org/feed/ - - https://webkit.org/blog/feed/ + - http://www.bing.com/HPImageArchive.aspx?format=rss&idx=0&n=1&mkt=en-US json: diff --git a/themes/default/layouts/_default/_markup/render-image.html b/themes/default/layouts/_default/_markup/render-image.html index 5dcfa80..1b73563 100644 --- a/themes/default/layouts/_default/_markup/render-image.html +++ b/themes/default/layouts/_default/_markup/render-image.html @@ -1,5 +1,5 @@ {{- $source := $.Destination | safeURL -}} -{{- $local := print "content/" $source -}} +{{- $public := print "public/" $source -}} {{- $remoteImage := resources.GetRemote $source -}} {{- $dimensions := "600x" -}} {{- $width := "" -}} @@ -8,8 +8,8 @@ {{- with $remoteImage -}} {{- with .Err -}} - {{- if fileExists $local -}} - {{- $localImage := imageConfig $local -}} + {{- if fileExists $public -}} + {{- $localImage := imageConfig $public -}} {{- with $localImage -}} {{- $width = .Width -}} {{- $height = .Height -}} diff --git a/themes/default/layouts/partials/feeds-generate.html b/themes/default/layouts/partials/feeds-generate.html index ab60435..068ad40 100644 --- a/themes/default/layouts/partials/feeds-generate.html +++ b/themes/default/layouts/partials/feeds-generate.html @@ -22,19 +22,23 @@ {{- $sourceLink := "https://example.com/" -}} {{- $sourceDescription := "No source description found." -}} {{- $date := now.Format "2006-01-02T15:04:05Z" -}} + {{- $enclosure := "" -}} {{ with .channel -}} - {{ if reflect.IsMap (index .link 0) -}} - {{ $sourceLink = index (index .link 0) "-href" -}} - {{ else -}} - {{ $sourceLink = index .link 0 -}} - {{ end -}} + {{ 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 }} {{ $sourceTitle = .title -}} {{ $sourceDescription = .description -}} - {{ if reflect.IsMap .item -}} {{ with .item }} {{ $title = index . "title" }} @@ -48,6 +52,9 @@ {{ $title = .title -}} {{ $link = .link -}} {{ $date = .pubDate -}} + {{ with .enclosure }} + {{ $enclosure = index . "-url" -}} + {{ end }} {{ end -}} {{ end }} @@ -89,6 +96,7 @@ "FeedDateTitle" ($date | plainify | htmlUnescape | time.Format "Monday, January 2 2006 at 15:04:05 MST") "FeedDescription" ($description | plainify | htmlUnescape) "FeedDescriptionShort" (delimit (first 1 (split ($description | plainify | htmlUnescape) "\n")) " " | truncate 250) + "FeedEnclosure" ($enclosure | plainify | htmlUnescape) "FeedLink" ($link | plainify | htmlUnescape) "FeedName" (delimit ((delimit (first 3 (split ($sourceTitle | plainify | htmlUnescape) " ")) " ") | findRE "^([^.|:|?|!]+)") " " | replaceRE "[^a-zA-Z ]" "") "FeedSourceDescription" ($sourceDescription | plainify | htmlUnescape) @@ -144,6 +152,26 @@ {{ $content = .FeedTitle }} {{ end }} + {{ $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 }} + {{ end }} + {{ end }} + {{ $markdown := resources.ExecuteAsTemplate $path (dict @@ -152,6 +180,7 @@ "date" .FeedDateTime "description" $description "domain" .FeedSourceDomain + "enclosure" $enclosure "image" $imageSource "link" .FeedLink "name" .FeedName -- cgit v1.2.3