I wanted to have multiple RSS feed, one which only show post in current section, and another feed which recursively include all content of this section(such as listing post of a section that is under this section).
Instead of the traditional single RSS for each page Hugo uses by provides.
Using multiple RSS feeds instead of just one allows for ease of visitors to subscribe to a whole section for all the posts within it.

The ugly way

It’s totally possible to create a post all-rss.md which uses a custom layout and outputs custom RSS, and turning off HTML from outputs and _build.list: never.
But the URL would be /post/all-rss/index.xml which is serviceable but ugly, and also wouldn’t play nicely with Hugo built-in alternative format support.

Doing it properly

So with that non-option out of the way, I decided to do it properly…

Adding custom output into config.toml

To start I would need to define a new custom output format for the new RSS type in outputFormats as per output format definition.

[outputFormats]
  [outputFormats.rss-recursive] #the name
    mediaType = 'application/rss+xml' #the media type
    baseName = 'index.all' #the base name
    rel = 'alternate'
    isPlainText = false
    isHTML = false
    noUgly = true
    permalinkable = false

This creates a custom format named rss-recursive with type of xml and base name of index.all, and it would be accessed as index.all.rss

I choose another name as RSS would have been taken by the default format, and I don’t want to overwrite that, I just needed a different basename that won’t conflict with the default index.rss, that’s why index.all was chosen, it’s simply an alternate non-conflicting name.

Adding custom format

Next is the part that stumped me, originally I tried things like $name.$format but apparently what I needed was list.$name.$format.
In my case the file name should be list.rss-recursive.xml, I am still uncertain, but it works for me, so I am just going to take it.
Now you can put your altered RSS generation code that includes recursive content(you will have to find your own here).

In case where you are targeting different types of pages, refer to templates lookup order for output formats.

Adding custom outputs

Now you just need to add it into the outputs of your site config.

[outputs]
  section = ["HTML", "RSS", "JSON","rss-recursive"]

For me, I added rss-recursive as another type but only for sections(as it wouldn’t make sense for others).
In case where you rather have it enabled on specific pages, you should overwrite the outputs via Front Matter for that individual page then

If all goes well you shouldn’t get any errors like

WARN found no layout file for “rss-recursive” for kind “section”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

Checking it out

All that’s left is just checking it out by navigating to it’s $name.$format in my case index.all.rss

Also note: you should check if your theme supports listing alternative output formats in your HTML meta tags to make sure other tools can discover them properly.

While in this article, I am using it to support multiple output format of the same type rss, the premises should be the same for everything else.

Resources

Here’s some resource that helped me on figuring out how to make this work.