Skip to content

Commit

Permalink
Tweak the RSS feed
Browse files Browse the repository at this point in the history
The default RSS template comes from
https://gohugo.io/templates/rss/#the-embedded-rss-xml

* Limit the number of items (it's unlimited by default)
* Rename the feed from "index.xml" to "feed.xml"
* Provide the full content of each post instead of a summary
* Change the title and description of the feed
* Add a link to the feed at the bottom of each post
  • Loading branch information
dguo committed Dec 27, 2018
1 parent 7aaebed commit 2001465
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ googleAnalytics: UA-90320718-1
languageCode: en-us
pygmentsCodefences: true
pygmentsStyle: monokai
rssLimit: 20
title: Danny Guo

outputFormats:
Expand All @@ -17,11 +18,13 @@ outputFormats:
isPlainText: true
mediaType: "application/json"
notAlternative: true
RSS:
mediatype: application/rss
baseName: feed

outputs:
home:
- HTML
- RSS
- Algolia

params:
Expand Down
26 changes: 26 additions & 0 deletions layouts/blog/rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ .Site.Author.name }}</title>
<link>{{ .Permalink }}</link>
<description>Blog posts by {{ .Site.Author.name }}</description>
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{ with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{ end }}
{{ range .Pages }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
<guid>{{ .Permalink }}</guid>
<description>{{ .Content | html }}</description>
</item>
{{ end }}
</channel>
</rss>
2 changes: 2 additions & 0 deletions layouts/blog/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ <h1>{{ .Title }}</h1>
<hr class="separator">

<p class="edit-message">
Subscribe to <a href="{{ "/blog/feed.xml" | absURL }}" type="application/rss+xml">this RSS feed</a> for more posts.
<br>
Found an error or typo? Feel free to open a pull request on
<a href="{{ .Site.Params.sourceCodeRepo }}/content/{{ .File.Path }}">GitHub</a>.
</p>
Expand Down

0 comments on commit 2001465

Please sign in to comment.