Wrangling Hugo's RSS templates
I just lost an hour “fixing” Hugo’s handling of RSS feeds.
Hugo’s default rss template only includes each post’s .Summary
, but I want to include the full .Content
. There is no configuration setting for this, so in order to include full post content I have to override the entire template. This seems nuts to me, but whatever. I had already done this a while ago and it’s worked fine…until I updated Hugo to v0.55.0.
Hugo’s 0.55.0 release introduced (what I consider) a breaking change which caused the RSS feed to include all posts. The rssLimit
configuration setting was replaced by a [services.rss]
which relies on Config.Services.RSS.Limit
. I wish someone would’ve told me. To be fair, there is something about this in the release notes but it’s not obvious and doesn’t call anything out as a breaking change, so I missed it.
I dutifully changed my settings to match, but it didn’t fix the problem. Of course it didn’t, because I’d overridden the default template and my version had no idea about Config.Services.RSS.Limit
. The default RSS template is internal to Hugo but is shown in the documentation. I copied it over my own template, re-did my change to .Summary
but still no luck. My RSS feed was still showing all posts. Turns out the version in the docs was wrong. Instead, I poked around the code and found the actual source for the default RSS template and copied that to ./layouts/index.rss.xml. Finally, I was again seeing full content and only the first 20 posts in the feed.
The problem then was that the feed contained entries for other non-post files that I’d edited. I only want posts in the feed, so I had to make an additional change to the template. The default is…
|
|
I changed mine to…
|
|
Here’s my final version of the template.
|
|
And in config.toml I’ve replaced rssLimit
with this…
|
|
If there’s an easier way to do all this I’d love to hear about it. Maybe the addition of the new [services.rss]
section suggests other pending improvements. Ideally, I wouldn’t need to override the entire RSS template in order to make these changes. And I’ll be sure to read the release notes more thoroughly next time.