mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
Improve RSS feeds
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
---
|
||||
title: News
|
||||
outputs:
|
||||
- html
|
||||
- rss
|
||||
aliases: [/release-notes/]
|
||||
---
|
||||
|
||||
@@ -29,7 +29,7 @@ ID = 'G-MBZGKNMDWC'
|
||||
|
||||
[outputs]
|
||||
home = ["HTML", "RSS", "REDIR", "HEADERS"]
|
||||
section = ["HTML", "RSS"]
|
||||
section = ["HTML"]
|
||||
|
||||
[mediaTypes]
|
||||
[mediaTypes."text/netlify"]
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>Hugo News</title>
|
||||
<description>Recent news about Hugo, a static site generator written in Go, optimized for speed and designed for flexibility.</description>
|
||||
<link>{{ .Permalink }}</link>
|
||||
<generator>Hugo {{ hugo.Version }}</generator>
|
||||
<language>{{ or site.Language.LanguageCode site.Language.Lang }}</language>
|
||||
{{- with site.Copyright }}
|
||||
<copyright>{{ . }}</copyright>
|
||||
{{- end }}
|
||||
{{- with .OutputFormats.Get "RSS" }}
|
||||
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .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 }}
|
||||
<lastBuildDate>{{ (index $news_items 0).PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
|
||||
|
||||
{{- /* Render items. */}}
|
||||
{{- range $news_items }}
|
||||
<item>
|
||||
<title>{{ .Title }}</title>
|
||||
<link>{{ .Permalink }}</link>
|
||||
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
|
||||
<guid>{{ .Permalink }}</guid>
|
||||
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
|
||||
</item>
|
||||
{{- end }}
|
||||
</channel>
|
||||
</rss>
|
||||
+2
-10
@@ -1,16 +1,8 @@
|
||||
|
||||
|
||||
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
{{- $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>{{ $title }}</title>
|
||||
<description>{{ $description }}</description>
|
||||
<title>Hugo News</title>
|
||||
<description>Recent news about Hugo, a static site generator written in Go, optimized for speed and designed for flexibility.</description>
|
||||
<link>{{ .Permalink }}</link>
|
||||
<generator>Hugo {{ hugo.Version }}</generator>
|
||||
<language>{{ or site.Language.LanguageCode site.Language.Lang }}</language>
|
||||
|
||||
Reference in New Issue
Block a user