Hugo Site.RSSLink Is Deprecated

Posted July 6, 2023 in hugo
Reading time: 1 minute

I haven’t posted here in quite some time. When I fired up hugo today to make a small tweak, I got this warning:

WARN  Site.RSSLink is deprecated and will be removed in a future release. Use the Output Format's Permalink method instead, e.g. .OutputFormats.Get "RSS".Permalink

I need the top-level RSS URL in my blog pages because I only want to have one top-level RSS feed, not one per hierarchy level as hugo likes to spit out.

Fortunately, after a little digging, I found a simple fix on the support forums.

In my head.html template, I had the following declaration:

<!-- RSS. Only ever link to /feed.xml. Render home, section, and pages. -->
{{- with .OutputFormats.Get "rss" -}}
    {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type $.Site.RSSLink $.Site.Title | safeHTML }}
{{- end }}

$.Site.RSSLink has been deprecated by the maintainers, but fortunately one of them provided a simple solution:

<!-- RSS. Only ever link to /feed.xml. Render home, section, and pages. -->
{{- with site.Home.OutputFormats.Get "rss" -}}
    {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }}
{{- end }}

All we have done is replace with .OutputFormats.Get with with site.Home.OutputFormats.Get, and $.Site.RSSLink with .RelPermalink .Permalink.

Note that .RelPermalink will render a relative URL, which is fine for this use case.

2024-01-05: Turns out it is fine for browsers, but not for tools that parse the link element to get the href attribute. Browsers will convert the relative link to a fully-qualified URL; tools likely will not. To make it easier for tools, use .Permalink instead.

I hope this helps anyone else that runs into this issue.



Comments

comments powered by Disqus