Skip to content

Commit 8db8333

Browse files
committed
RSS feed
1 parent 6e9b552 commit 8db8333

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

config.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ params:
2020
hideMadeWithLine: true
2121
meta:
2222
favicon: true
23+
author: Basile Simon
2324

2425
permalinks:
2526
news: "/news/:slug"
2627

2728
outputs:
2829
home:
29-
- "HTML"
30-
- "RSS"
30+
- html
31+
news:
32+
- html
33+
- feed
34+
outputFormats:
35+
feed:
36+
baseName: index
37+
mediaType: application/rss+xml
38+
isPlainText: false
39+
isHTML: false

layouts/_default/rss.xml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 = $pctx.RegularPages }}
26+
{{- else }}
27+
{{- $pages = $pctx.Pages }}
28+
{{- end }}
29+
{{- $limit := .Site.Config.Services.RSS.Limit }}
30+
{{- if ge $limit 1 }}
31+
{{- $pages = $pages | first $limit }}
32+
{{- end }}
33+
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
34+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
35+
<channel>
36+
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ .Site.Title }}{{ end }}</title>
37+
<link>{{ .Permalink }}?campaign=rss</link>
38+
<author>{{ .Site.Params.author }}</author>
39+
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ .Site.Title }}</description>
40+
<generator>Hugo</generator>
41+
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }}
42+
<copyright>{{ . }}</copyright>{{ end }}{{ if not .Date.IsZero }}
43+
<lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
44+
{{- with .OutputFormats.Get "RSS" }}
45+
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
46+
{{- end }}
47+
{{- range $pages }}
48+
<item>
49+
<title>{{ .Title }}</title>
50+
<link>{{ .Permalink }}?campaign=rss</link>
51+
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
52+
<author>{{ .Site.Params.author }}</author>
53+
<guid>{{ .Permalink }}</guid>
54+
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
55+
</item>
56+
{{- end }}
57+
</channel>
58+
</rss>

0 commit comments

Comments
 (0)