From 543329a1fdcae0fb3e07ae6fd89f083414089d68 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Sat, 15 Jun 2024 18:51:33 -0400 Subject: [PATCH] Fix RSS feed parsing (#713) ## Which problem is this PR solving? - Resolves #710 - Replaces #711 ## Description of the changes - Remove the use of JSON proxy server, read RSS as XML directly - Change field names accordingly ## How was this change tested? - locally `make develop` Signed-off-by: Yuri Shkuro --- themes/jaeger-docs/layouts/index.html | 22 +++++++++++++------ .../layouts/partials/home/articles.html | 5 ++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/themes/jaeger-docs/layouts/index.html b/themes/jaeger-docs/layouts/index.html index a4c21560..bec72d70 100644 --- a/themes/jaeger-docs/layouts/index.html +++ b/themes/jaeger-docs/layouts/index.html @@ -1,16 +1,23 @@ {{ define "main" }} -{{ $json := "" }} -{{ with resources.GetRemote "https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/jaegertracing" }} - {{ $json = . | transform.Unmarshal }} +{{ $rss := "" }} +{{ with resources.GetRemote "https://medium.com/feed/jaegertracing" }} + {{ with .Err }} + {{ errorf "%s" . }} + {{ else }} + {{ $rss = . | transform.Unmarshal }} + {{ end }} {{ end }} -{{ $posts := first 100 $json.items }} -{{ $imgLinks := slice }} + +{{/* Parse image links */}} {{ $defaultImgLink := "/img/jaeger-icon-color.png" }} +{{ warnf "Downloaded RSS feed for: %v" $rss.channel.title }} +{{ $posts := first 20 $rss.channel.item }} +{{ $imgLinks := slice }} -{{/* Parse Medium's post first image link */}} {{ range $k, $v := $posts }} {{ $imgLink := $defaultImgLink }} - {{ with strings.FindRESubmatch "]+src=\"([^\">]+)\"" (index $v "content") 1 }} + {{ $content := index $v "encoded" }} + {{ with strings.FindRESubmatch "]+src=\"([^\">]+)\"" $content 1 }} {{ if . }} {{/* If image found in post */}} {{ $findMatch := index . 0 }} {{/* Choose the first image */}} {{ with $findMatch }} @@ -22,6 +29,7 @@ {{ end }} {{ end }} {{ $imgLinks = $imgLinks | append $imgLink }} + {{ warnf "Post: %v" $v.title }} {{ end }} {{ partial "home/hero.html" (dict "posts" $posts "title" site.Title "tagline" site.Params.tagline "latestVersion" site.Params.latest) }} diff --git a/themes/jaeger-docs/layouts/partials/home/articles.html b/themes/jaeger-docs/layouts/partials/home/articles.html index 35d9a45d..e3a786dc 100644 --- a/themes/jaeger-docs/layouts/partials/home/articles.html +++ b/themes/jaeger-docs/layouts/partials/home/articles.html @@ -8,11 +8,10 @@

Latest articles from our blog

{{ $link := .link }} {{ $img := (index $.imgLinks $idx) }} {{ $title := .title | plainify }} - {{ $author := .author }} + {{ $author := .creator }} {{ $dateRaw := .pubDate }} {{ $date := dateFormat "January 2, 2006" $dateRaw }} - {{ $summary := .content | plainify | truncate 150 }} - + {{ $summary := .encoded | plainify | truncate 150 }}