rssLimit not working in Hugo 0.55

Hello Hugo users,

I just updated from 0.54 to 0.55 and got the following warning when building my website:

Page's .RSSLink is deprecated and will be removed in a future release. Use the Output Format's link, e.g. something like:
    {{ with .OutputFormats.Get "RSS" }}{{ . RelPermalink }}{{ end }}.

So I changed

{{- if .RSSLink }}
<link href="{{ .RSSLink }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
{{- end -}}

to

{{- if .OutputFormats.Get "RSS" }}
<link href="{{ .OutputFormats.Get "RSS" }}" rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}" />
{{- end -}}

in my head.html partial and the warning message disappeared.

But now rssLimit = 10 from my config.toml does not seem to work anymore: instead of the limit set up in my config, all posts show up in the xml file. Even with the deprecated .RSSLink in my partial, rssLimit does not work anymore in Hugo 0.55.

Does anyone have an idea what I’m doing wrong?

Many thanks in advance.

somnium

That config option is removed in 0.55. Read the “Notes” section in the release notes. In short, you need to do something ala:

{{- $pages := .Data.Pages -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}

In your template.

And for people asking “why on earth do you need to add these breaking changes”:

We used to have lots of special code paths and a different rendering implementation for some of the output formats (e.g. RSS). Now we have more or less 1 simple function. Which means less code to maintain and test.

1 Like

These config.toml settings will work with the default RSS template:

[services.rss]
limit = 15
1 Like

I’m pretty sure that rssLimit will also work with the internal template – my answer above was re. custom templates.

I’m very sorry, but I forgot to mention that I’m using a custom RSS template which is located in layouts/_default/rss.xml (because I need the full content of my posts in the RSS feed).

[services.rss]
limit = 15

…does not seem to work with custom RSS templates but it works pretty well with the default template. As bep just wrote, even

rssLimit = 10

…still works with the custom RSS template in Hugo 0.55.

And even my custom RSS template works with 0.55 but it shows all posts in the feed.

So my problem is, I think, the custom RSS template thing.

This is what I did now: I copied the following code to the top of my custom RSS template (which was not there before):

{{- $pages := .Data.Pages -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}

But I still don’t understand how to limit the number of posts shown in the RSS feed. What else do I have to change to limit the number of posts to 10?

I would be very happy to receive further suggestions.

Thank you very much
somnium

I hate to just +1, but I’m also having the same issue. I have added the code to the top of my custom rss.xml template, added the [services.rss] config, and I’m still seeing all posts show up in my RSS feed. What else needs to be done? Thanks for any help!

Thanks for the discussion, it made me realise that updating to 0.55.0 had blown out my podcast RSS feed.

I think I’ve got it working now - https://github.com/funkydan2/alpha-church/blob/master/layouts/sermons/sermons.rss.xml

In my params, I just have rssLimit = 100 and the output is limited to 100 episodes.

2 Likes

D’oh! I didn’t change my range to use the $pages variable. I’m a dummy. Thanks @funkydan2, your example let me see my mistake.

Apparently I’m a dummy, too. :man_facepalming: :sweat_smile:

That’s what did the trick. Thank you very much, @funkydan2 and @BrianPeek! :slightly_smiling_face: :+1: