Skip to content

Commit 78818c7

Browse files
authored
fix(rss): update RSS template and Hugo version for compatibility (#417)
Hugo v0.156.0 removed the deprecated .Site.Author field, breaking the RSS template. Align the RSS template with Hugo's current embedded default by using site.Params.author, transform.XMLEscape, .PublishDate, and proper lastBuildDate computation. Bump CI Hugo version from 0.151.0 to 0.157.0. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent 1381370 commit 78818c7

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

.github/workflows/hugo_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Setup Hugo
3737
uses: peaceiris/actions-hugo@v2
3838
with:
39-
hugo-version: "0.151.0"
39+
hugo-version: "0.157.0"
4040
extended: true
4141

4242
- name: Build

layouts/home.rss.xml

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,59 @@
1-
{{- $pctx := . -}}
2-
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
3-
{{- $pages := slice -}}
4-
{{- if or $.IsHome $.IsSection -}}
5-
{{- $pages = where $pctx.RegularPages "Type" "blog" -}}
6-
{{- else -}}
7-
{{- $pages = where $pctx.Pages "Type" "blog" -}}
8-
{{- end -}}
9-
{{- $limit := .Site.Config.Services.RSS.Limit -}}
10-
{{- if ge $limit 1 -}}
11-
{{- $pages = $pages | first $limit -}}
12-
{{- end -}}
1+
{{- $authorEmail := "" }}
2+
{{- with site.Params.author }}
3+
{{- if reflect.IsMap . }}
4+
{{- with .email }}
5+
{{- $authorEmail = . }}
6+
{{- end }}
7+
{{- end }}
8+
{{- end }}
9+
10+
{{- $authorName := "" }}
11+
{{- with site.Params.author }}
12+
{{- if reflect.IsMap . }}
13+
{{- with .name }}
14+
{{- $authorName = . }}
15+
{{- end }}
16+
{{- else }}
17+
{{- $authorName = . }}
18+
{{- end }}
19+
{{- end }}
20+
21+
{{- $pctx := . }}
22+
{{- if .IsHome }}{{ $pctx = .Site }}{{ end }}
23+
{{- $pages := slice }}
24+
{{- if or $.IsHome $.IsSection }}
25+
{{- $pages = where $pctx.RegularPages "Type" "blog" }}
26+
{{- else }}
27+
{{- $pages = where $pctx.Pages "Type" "blog" }}
28+
{{- end }}
29+
{{- $limit := .Site.Config.Services.RSS.Limit }}
30+
{{- if ge $limit 1 }}
31+
{{- $pages = $pages | first $limit }}
32+
{{- end }}
1333
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
1434
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
1535
<channel>
16-
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
36+
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ .Site.Title }}{{ end }}</title>
1737
<link>{{ .Permalink }}</link>
18-
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
19-
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
20-
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
21-
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
22-
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
23-
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
24-
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
25-
{{- with .OutputFormats.Get "RSS" -}}
38+
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ .Site.Title }}</description>
39+
<generator>Hugo</generator>
40+
<language>{{ site.LanguageCode }}</language>{{ with $authorEmail }}
41+
<managingEditor>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
42+
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with .Site.Copyright }}
43+
<copyright>{{ . }}</copyright>{{ end }}{{ if not .Date.IsZero }}
44+
<lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
45+
{{- with .OutputFormats.Get "RSS" }}
2646
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
27-
{{- end -}}
28-
{{ range $pages }}
47+
{{- end }}
48+
{{- range $pages }}
2949
<item>
3050
<title>{{ .Title }}</title>
3151
<link>{{ .Permalink }}</link>
32-
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
33-
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
52+
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
53+
{{- with $authorEmail }}<author>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</author>{{ end }}
3454
<guid>{{ .Permalink }}</guid>
35-
<description>{{ .Summary | html }}</description>
55+
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
3656
</item>
37-
{{ end -}}
57+
{{- end }}
3858
</channel>
3959
</rss>

0 commit comments

Comments
 (0)