Enable Full Content RSS

2017/09/05

I myself am a RSS lover, and of course, feeds of full content are always preferred. However, hugo has changed its built-in rss template from full content to summary only since 0.20, which seems unreasonable to me.

Here is how I get the full content feeds back, and it’s really easy.

What you need to do is to create your own RSS template. Hugo look up RSS templates in an order like this:

1. /layouts/section/<section>.rss.xml
2. /layouts/_default/rss.xml
3. /themes/<theme>/layouts/section/<section>.rss.xml
4. /themes/<theme>/layouts/_default/rss.xml

Below is hugo’s built-in template for rss. You can find it at Hugo Docs or gohugoio/hugo - github

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ if eq  .Title  .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
    <link>{{ .Permalink }}</link>
    <description>Recent content {{ if ne  .Title  .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</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 .Data.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>{{ .Summary | html }}</description>
    </item>
    {{ end }}
  </channel>
</rss>

Only one place to change. That is

From

<description>{{ .Summary | html }}</description>

to

<description>{{ .Content | html }}</description>

Save the template as rss.xml, and you are all done.

BTW, some guy is making a pull request at github, adding the option to choose from summary and full content. Let’s hope that he will succeed.