Creating a single-purpose RSS feed

I have an existing site with an RSS feed at /index.xml for blog posts, which I don’t want to change. I want to create a couple of new RSS feeds for specific purposes:

The first is the same posts as the standard RSS feed, but instead of using .Content it will use .Summary. I want this to be located at /summary.xml

The second will have only specific pages on a topic (say, penguins) and will be located at, say, /penguins.xml. I’m planning to create a “menu” and in each page’s front matter that I want in this feed, I’ll just say “menu: penguins” and then reference that menu in the RSS template.

My question is not how to write the templates - that seems easy and I’m having no trouble copying and modifying the standard RSS template - my question is how to get the rendered site to have these specific paths and content. I’m having no luck searching; perhaps I haven’t thought of the right search terms. I’ve tried a few options, without success:

  1. Put a file into /content/summary.xml, for example, and put template code in it. Doesn’t work, it just gets copied as a static file to the output.
  2. Put a file into /static/summary.xml, but the same problem happens.
  3. Put a markdown file into /content, mostly empty and perhaps just with front matter; and let it be rendered with a template where the logic will live; but it’s not a page or blog; what content type would I specify for it? Not sure where to start with this idea.

For this you would have to look into https://gohugo.io/templates/output-formats

The normal use case is to define RSS as an extra output format for a given page, but if you want many feeds, you may want to just create a bunch of “single pages” and set outputs and either Type or Layout in front matter to pick the correct template.

Thank you! Let me check if I understand. I’ll focus just on the penguins feed as an example. If I can get this working I’m sure I can do the other one too. I’ll take the following steps:

  1. Create content/penguins.md with the following contents:

    date: 2018-03-19
    layout: penguins
    outputs:
    - rss
  2. Create layouts/penguins/list.xml with contents like the following:
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> ... {{ range first 20 .Site.Menus.penguins }} ...

But how do I get Hugo to render this single page penguins.md with the list layout template? I’m not sure about that.

  • Your penguins.md will resolve to a regular page in Hugo (single page, leaf page, many names …)
  • See https://gohugo.io/templates/lookup-order/
  • So, you have Type (defaults to section) and Layout you can use to control what template. With your example a layout in layouts/_default/penguins.xml should work, but there are many options here.

I’m a little confused. Should I set type: section and layout: penguins in front matter to get it to choose that template?

No …

So, Hugo tries to find the most specific template.

We use Type and Layout as some of the criterias.

Layout is considered “most specific” – so no need to mess with other settings if that is good enough.

Thanks. I’m still working on deciding the best way to do this from the several options. One option for the penguins feed, for example, is simply to create a new taxonomy and have it rendered only as RSS, so each post that I want in the penguins RSS feed could simply add this in the front matter. This is seeming like a simpler way to go at the moment:

feeds:
- Penguins

SOLVED It took a while but I got around to doing this. It was pretty simple, I was just confused about the different options and how they were different from each other.

Short version: create a content file with a layout parameter in front matter. The value of that parameter should match the name of a layout file under layouts/_default/.

Real example Git commit where I got this working: https://github.com/xaprb/story/commit/6e31bfaf5afbabfcb184447454d7e2801f67fd9c This produces a special-purpose RSS feed at the URL /mailchimp/index.xml

3 Likes