How can I change the RSS URL?

I’ve named my section “post”, so the RSS URL generated by Hugo is /post/index.xml. I want it to be /feed/index.xml. Is this possible?

I tried the naive approach of adding a content/feed/index.xml file with my RSS template but it didn’t like that.

You can’t. Indexes are always in the root of the content that they index. (index.html, index.xml)

Bummer. I guess I’ll just use a post-build script to move the file where I want it. I don’t want RSS feeds generated for my tags either so I can have a script delete those as well.

It’d be nice to have a little more control over this in the future. Do you have any plans in this area?

Is there any way to do this yet? By default Hugo generates RSS at “http://baseurl.com/index.xml”, but when migrating TO Hugo, it’d be nice to avoid having to have everyone re-subscribe when the old URL is, for example, “http://baseurl.com/feed.xml”.

What you want is possible (which is a different requirement than the thread starter).

I would suggest you re-define the RSS output format (look at the docs). There is also the RSSUri setting, but that will be deprecated and removed sone.

Sorry, it looked like the same answer I was looking for, but the Output Formats documentation is very confusing, as it’s blended with Media Types and has no actual usable examples. Are there any such examples I could take a look at?

Media types and output formats are very much connected. Documentation will eventually improve, examples will come – for now I can only hint that you need to create a RSS output format definition with feed as the baseName.

@codydh I have been toying around with custom outputs and figured out a way to create a feed.xml for the homepage. I’ll delimit the steps here—I need to improve the documentation as well—but this should provide enough insight to get you going on doing the same for your individual sections, etc. Keep in mind this is my first time using this features, so YMMV:

In your site’s config.toml, place the following:

[outputs]
home = ["HTML","FEED"]

[mediaTypes]
[mediaTypes."application/rss"]
suffix = "xml"

[outputFormats]
[outputFormats.FEED]
mediatype = "application/rss"
baseName = "feed"

Notice how you define that the Kind of home specifically outputs HTML (default behavior) as well as FEED. You need to declare these explicitly, and although they are all uppercase, output formats are case insensitive.

You can then create your layout for the homepage RSS feed at layouts/index.feed.xml. When your site builds, it will output whatever templating you put inside of this layout at codydhsite.com/feed.xml. For your use case, section is also a Kind, so you could create a similar layout/template at layouts/_default/section.feed.xml and then set the section kind accordingly in your site’s configuration file…

HTH.

I’m looking to @bep to confirm if I’m on the right track since this is what I’ve figure out for potential improvements to the docs in this area.

1 Like

No, that isn’t how I would do it.

Remove all but this:

[outputFormats]
[outputFormats.RSS]
mediatype = "application/rss"
baseName = "feed"
```

The above should _redefine_ the built-in output format `RSS`, and then you don't have to add anything else.
2 Likes

Is my issue that I treated RSS like a fully custom output rather than one of Hugo’s built-in media types? So, for example, if @codydh wanted to make codydhsite.com/mycrazyfile.onetwothree, that would require additions similar to the above?

The question was “How can I change the RSS URL?” A simple question should not need a two page manual.

A simple question should also have a related answer. Here is my question, again:

I’m asking about my mistake so that I can make it easier to grok in the docs. This requires I understand it better myself.

Your answer worked – and is of course relevant when you want to create a custom feed (say you want both Atom and RSS … or whatever); but for this particular question it felt a little too much.

Thank you for your feedback @bep. I’m getting a better idea of usage now.

Ok, I apologize if I’ve missed something here. What I’ve done is added the following to my site’s config.toml:

[outputFormats]
[outputFormats.RSS]
mediatype = "application/rss"
baseName = "feed"

I tried this alone, as well as adding the stock rss template from the documentation to a file index.feed.xml. However, the only thing that’s generated is the usual /index.xml.

If I use the full config.toml additions that @rdwatters had suggested:

[outputs]
home = ["HTML","FEED"]

[mediaTypes]
[mediaTypes."application/rss"]
suffix = "xml"

[outputFormats]
[outputFormats.FEED]
mediatype = "application/rss"
baseName = "feed"

And then generate the site, again with the /layouts/index.feed.xml in place, I do get a /feed.xml generated.

Am I missing something here?

Yea, I posted it without testing it. Seems like that to redefine the RSS, it must also be in a outputs list, i.e.

[outputs]
home = [ "RSS"]

It seems like the default list (when not outputs are set) gets its definition from the built-in list, which is a little surprising, will fix that.

1 Like

If I only include in my config.toml the following chunks:

[outputs]
home = [ "RSS"]

[outputFormats]
[outputFormats.RSS]
mediatype = "application/rss"
baseName = "feed"

I wind up with no /index.html, only a /feed.xml. I had to instead specify:

[outputs]
home = [ "RSS", "HTML"]

[outputFormats]
[outputFormats.RSS]
mediatype = "application/rss"
baseName = "feed"

Which seems to do the job! The only thing now is that {{ .Site.RSSLink }} still winds up pointing to /index.xml, but this can obviously be worked around.

The RSSLink is unfortunate (and I make a note of that, you can maybe work around that by setting the RSSUri), but I would recommend having a look at the OutputFormats and AlternativeOutputFormats when creating links to “other formats”.

I am trying to change the url to my RSS feed to be:
/news.rss

I’m using the following configuration:

outputs:
  home: ["HTML","RSS"]

mediaTypes:
  "application/rss":
    suffix: "rss"

outputFormats:
  RSS:
    mediatype: "application/rss"
    baseName: "news"

which does generate the /news.rss file - however, I cannot figure out where to place/name the template for this.

I have tried:

  • layouts/index.xml
  • layouts/news.rss
  • layouts/index.news.rss
  • layouts/news.xml
  • layouts/index.rss

to no avail. If I comment out the config above, restoring RSS functionality to the defaults, then my template at:

layouts/rss.xml

works fine.

What am I missing?

Try layouts/rss.xml