Adding full post content in hugo RSS

This website was created with Hugo. It comes with a built-in RSS generator, which is great, but it lacks the XML tag with the full post content, which is definitely useful for RSS readers - if I’m using a RSS client to read a blog post I’d like to have all this experience within that client.

I recently opened a Pull Request to add it into their repository, but it seems they don’t want to. Currently, at least prior to Hugo 0.147.8, which is the latest Hugo version at the time of this post, it comes just with a <description> tag, which displays just a summary. Fortunately, this can be changed by overriding the default rss template.

First, you have to get the default template in their repository. At the moment, it’s located in tpl/tplimpl/embedded/templates/rss.xml. Create the file rss.xml in your layouts/_default/ directory and copy the default template to it.

At the end of the file, you’ll see the description tag. Add the following tag below it:

<content:encoded>
  {{ .Content | transform.XMLEscape | safeHTML }}
  {{ $authorEmail := site.Params.rssEmail }}
  {{ printf `<![CDATA[<a href="mailto:%s?subject=%s">Reply to this post by email</a>]]>` $authorEmail .Title | safeHTML }}
</content:encoded>

This snippet adds a new line at the end of the text (only in the feed), like this: example

It requires a field in your hugo.toml:

[params]
rssEmail = "[email protected]"

If you don’t want it, you can just remove these two lines and have only the full text.