Skip to content

Commit b6af9ed

Browse files
Imrprovements to RSS (#319)
* Copy hugo's internal rss template - loc: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml - at commit 5f42590144579c318a444ea2ce46d5c3fbbbfe6e of https://github.com/gohugoio/hugo/ * Add Site image from images param * Hide search and archives layouts from feed index * add Description and Summary in RSS as in other templates
1 parent ddf004b commit b6af9ed

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

layouts/_default/rss.xml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{{- $pctx := . -}}
2+
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
3+
{{- $pages := slice -}}
4+
{{- if or $.IsHome $.IsSection -}}
5+
{{- $pages = $pctx.RegularPages -}}
6+
{{- else -}}
7+
{{- $pages = $pctx.Pages -}}
8+
{{- end -}}
9+
{{- $limit := .Site.Config.Services.RSS.Limit -}}
10+
{{- if ge $limit 1 -}}
11+
{{- $pages = $pages | first $limit -}}
12+
{{- end -}}
13+
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
14+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
15+
<channel>
16+
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
17+
<link>{{ .Permalink }}</link>
18+
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
19+
{{- with $.Site.Params.images }}
20+
<image>
21+
<url>{{ index . 0 | absURL }}</url>
22+
<link>{{ index . 0 | absURL }}</link>
23+
</image>
24+
{{- end }}
25+
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
26+
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
27+
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
28+
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
29+
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
30+
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
31+
{{- with .OutputFormats.Get "RSS" -}}
32+
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
33+
{{- end -}}
34+
{{ range $pages }}
35+
{{- if and (ne .Layout `search`) (ne .Layout `archives`) }}
36+
<item>
37+
<title>{{ .Title }}</title>
38+
<link>{{ .Permalink }}</link>
39+
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
40+
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
41+
<guid>{{ .Permalink }}</guid>
42+
<description>{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end -}}</description>
43+
</item>
44+
{{- end }}
45+
{{ end }}
46+
</channel>
47+
</rss>

0 commit comments

Comments
 (0)