From 37c6954ac0e4fe925d6aabc3788d2d3466cecf87 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Tue, 9 Apr 2024 09:53:41 -0700 Subject: [PATCH] Improve RSS feeds --- content/en/news/_index.md | 3 ++ hugo.toml | 2 +- layouts/index.rss.xml | 68 +++++++++++++++++++++++++++++++++++++++ layouts/news/list.xml | 12 ++----- 4 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 layouts/index.rss.xml diff --git a/content/en/news/_index.md b/content/en/news/_index.md index bb2531dd6..a1959bd1d 100644 --- a/content/en/news/_index.md +++ b/content/en/news/_index.md @@ -1,4 +1,7 @@ --- title: News +outputs: + - html + - rss aliases: [/release-notes/] --- diff --git a/hugo.toml b/hugo.toml index 209231663..63cc32798 100644 --- a/hugo.toml +++ b/hugo.toml @@ -29,7 +29,7 @@ ID = 'G-MBZGKNMDWC' [outputs] home = ["HTML", "RSS", "REDIR", "HEADERS"] - section = ["HTML", "RSS"] + section = ["HTML"] [mediaTypes] [mediaTypes."text/netlify"] diff --git a/layouts/index.rss.xml b/layouts/index.rss.xml new file mode 100644 index 000000000..40bca59eb --- /dev/null +++ b/layouts/index.rss.xml @@ -0,0 +1,68 @@ +{{- printf "" | safeHTML }} + + + Hugo News + Recent news about Hugo, a static site generator written in Go, optimized for speed and designed for flexibility. + {{ .Permalink }} + Hugo {{ hugo.Version }} + {{ or site.Language.LanguageCode site.Language.Lang }} + {{- with site.Copyright }} + {{ . }} + {{- end }} + {{- with .OutputFormats.Get "RSS" }} + {{ printf "" .Permalink .MediaType | safeHTML }} + {{- end }} + + {{- $news_items := slice }} + + {{- /* Get releases from GitHub. */}} + {{- $u := "https://api.github.com/repos/gohugoio/hugo/releases" }} + {{- $releases := partial "utilities/get-remote-data.html" $u }} + {{- $releases = where $releases "draft" false }} + {{- $releases = where $releases "prerelease" false }} + {{- range $releases | first 20 }} + {{- $summary := printf + "Hugo %s was released on %s. See [release notes](%s) for details." + .tag_name + (.published_at | time.AsTime | time.Format "2 Jan 2006") + .html_url + }} + {{- $ctx := dict + "PublishDate" (.published_at | time.AsTime) + "Title" (printf "Release %s" .name) + "Permalink" .html_url + "Section" "news" + "Summary" ($summary | $.Page.RenderString) + }} + {{- $news_items = $news_items | append $ctx }} + {{- end }} + + {{- /* Get content pages from news section. */}} + {{- range .Pages }} + {{- $ctx := dict + "PublishDate" .PublishDate + "Title" .Title + "RelPermalink" .RelPermalink + "Section" "news" + "Summary" .Summary + "Params" (dict "description" .Description) + }} + {{- $news_items = $news_items | append $ctx }} + {{- end }} + {{- /* Sort, limit, and render lastBuildDate. */}} + {{- $limit := cond (gt site.Config.Services.RSS.Limit 1) site.Config.Services.RSS.Limit 999 }} + {{- $news_items = sort $news_items "PublishDate" "desc" | first $limit }} + {{ (index $news_items 0).PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} + + {{- /* Render items. */}} + {{- range $news_items }} + + {{ .Title }} + {{ .Permalink }} + {{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} + {{ .Permalink }} + {{ .Summary | transform.XMLEscape | safeHTML }} + + {{- end }} + + diff --git a/layouts/news/list.xml b/layouts/news/list.xml index 508323728..40bca59eb 100644 --- a/layouts/news/list.xml +++ b/layouts/news/list.xml @@ -1,16 +1,8 @@ - - {{- printf "" | safeHTML }} - {{- $title := printf "%s on %s" .Title site.Title }} - {{- $description := printf "Recent content in %s on %s" .Title site.Title }} - {{- if .IsHome }} - {{- $title = site.Title }} - {{- $description := printf "Recent content on %s" site.Title }} - {{- end }} - {{ $title }} - {{ $description }} + Hugo News + Recent news about Hugo, a static site generator written in Go, optimized for speed and designed for flexibility. {{ .Permalink }} Hugo {{ hugo.Version }} {{ or site.Language.LanguageCode site.Language.Lang }}