Creating single-purpose RSS feeds with Hugo

Featured image for sharing metadata for article

Tonight I've added a new couple of RSS feeds to my website - one for my /salary/ page and one for my /now page - for two pages that folks may want to keep an eye on more easily.

Because it was a little awkward to set up the feeds, I ended up wanting to write it up as a form of blogumentation.

To start with, we need to modify our Hugo config to indicate we've got a new content type:

[outputs]
home = ["...", "salaryRSS"]

[outputFormats]
[outputFormats.salaryRSS]
mediatype = "application/rss"
baseName = "salary"

This indicates to Hugo that this is an RSS feed, and to create a file called /salary.xml.

Then, we need to wire in the feed itself, by creating layouts/index.salaryrss.xml:

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Jamie Tanna's salary page</title>
    <link>{{ .Site.Params.LiveSiteUrl }}/salary/</link>
    <description>Updates to Jamie Tanna's salary page</description>
    <!-- ... -->
    <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
    <!-- ... -->
    {{ with .GetPage "salary" }}
    <item>
      <title>{{ .Title }}</title>
      <link>{{ .Site.Params.LiveSiteUrl }}{{ .Permalink }}?utm_medium=rss&amp;utm_source=rss</link>
      <pubDate>{{ .GitInfo.AuthorDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>

      <!-- ... ->
    </item>
    {{ end }}
  </channel>
</rss>

Notice that the template is layouts/index.salaryrss.xml, with a lowercase filename, as Hugo appears to require it be case sensitive.

Because we've wired in the updated date (via Git metadata) this means that each time there is an update to the page, the feed will be updated, and followers will see there's a new update on the page.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #hugo.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.