Skip to content

Commit e6369c3

Browse files
committed
feat: Add RSS feed generation
Added RSS feed and configured the limit.
1 parent 53807ba commit e6369c3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

hugo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,9 @@ priority = 0
123123
[Taxonomies]
124124
category = "categories"
125125
author = "authors"
126+
127+
######################### Services ###############################
128+
[services]
129+
[services.rss]
130+
# Number of items to include in the RSS feed.
131+
limit = 20

layouts/index.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- $pctx := . -}}
2+
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
3+
{{- $pages := slice -}}
4+
{{- $sectionsToInclude := (slice "blog" "workshops") -}}
5+
{{- $typesToInclude := (slice "student-talks" "hacking-hours") -}}
6+
7+
{{- range $pctx.RegularPages -}}
8+
{{- if and .Date (not .Date.IsZero) (or (in $sectionsToInclude .Section) (in $typesToInclude .Type)) (ne .Params.upcoming true) -}}
9+
{{- $pages = $pages | append . -}}
10+
{{- end -}}
11+
{{- end -}}
12+
13+
{{- $limit := .Site.Config.Services.RSS.Limit | default 20 -}}
14+
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
15+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
16+
<channel>
17+
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ .Site.Title }}{{ end }}</title>
18+
<link>{{ .Permalink }}</link>
19+
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ .Site.Title }}</description>
20+
<generator>Hugo</generator>
21+
<language>{{ site.Language.LanguageCode | default "en-us" }}</language>
22+
{{ with .Site.Lastmod -}}
23+
<lastBuildDate>{{ .Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
24+
{{- end -}}
25+
{{- with .OutputFormats.Get "RSS" -}}
26+
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
27+
{{- end -}}
28+
{{- range first $limit (sort $pages "Date" "desc") -}}
29+
<item>
30+
<title>{{ .Title }}</title>
31+
<link>{{ .Permalink }}</link>
32+
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
33+
<guid>{{ .Permalink }}</guid>
34+
<description>{{ .Description }}</description>
35+
</item>
36+
{{- end -}}
37+
</channel>
38+
</rss>

0 commit comments

Comments
 (0)