[SOLVED] Eliminate xml suffix | Custom RSS URI

Is there a way to hide the xml suffix from a Hugo feed?

My current Tumblr feed is found at http://onedrawingperday.com/rss

I have already configured my new Hugo site feed like this:

home = [ "HTML", "RSS"]
mediatype = "application/rss"
baseName = "rss"

However the feed is available under: /rss.xml and ideally I would like to have it under /rss so that my subscribers get the new feed automatically without having to inform them

I’ve tried the following without success:
suffix="" resolves to /rss.xml with the template under /layouts/index.rss.xml

suffix="rss" resolves as above even with the template as /layouts/index.rss

Is this possible?

If not I guess I’ll have to try an XML Level Redirect

No help needed. I just found out that Tumblr hides the suffix in the URL. The actual Tumblr feed is located under /rss.xml so I don’t think I’ll have a problem with feed readers as I have already named the new feed like the old one.

For future reference. What you can do is:

suffix = ""
delimiter = ""

mediatype = "application/customrss"
baseName = "rss"

Thank you! That is even better!

Like I said yesterday thanks to your input I am able to have the feed without the suffix under /rss but unfortunately I cannot find how to use a custom RSS template with this setup.

No matter what I do Hugo always ends up using the internal template.

I’ve tried the following template variations with no success:

And also I’ve tried all of the above under just /layouts/

The thing is that I really need a custom RSS template. And I am able to render it as needed under /rss.xml

The RSS is a little special in the layouts department (I kept it this way to avoid breaking stuff), so when you redefine that output format you may end up with some surprises.

What I suggest you do is something ala:

home = [ "HTML", "CUSTOMRSS" ]

suffix = ""
delimiter = ""

mediatype = "application/customrss"
baseName = "rss"

The above should give you less surprises.

Also see https://gohugo.io/templates/output-formats/#output-formats-for-pages

Right. I understand. With the above in the site’s config.toml I was able to turn off Hugo’s internal RSS template.

But no dice. The feed is not generated now at all. It gives me a 404.

I cannot figure out how to name the template for the CUSTOMRSS Output Format and where to put it.

Again I tried several variations like customrss and customrss.xml under /layouts/_default but I always get a blank page.

Anyway thanks for your help.

I’ve already spent way too much time on this. I’m calling it a day.

If you have your site sourceo online, I can look at it.

1 Like

Thanks @bep but I just made it!

The solution was in the post of this thread: How to use the new Custom Output Formats

I simply named the template list.customrss under /layouts/_default/ and BINGO! The custom RSS feed was rendered.

In my config.toml I used exactly what you posted above.

This info is already in the docs in the table for the different Output Formats example: https://gohugo.io/templates/output-formats/#link-to-output-formats

But it wasn’t that clear. I think I’ll send a pull request for the Docs as soon as I have more time to make this plain and simple. To include a phrase like this one:

The naming of an Output Formats template follows the same pattern that is used for standard Hugo templates. eg. list.[kind].[suffix] under /layouts/_default or index.[kind].[suffix] under /layouts/

A final note just for aesthetic purposes.

That CUSTOMRSS Output Format is a bit of an eyesore.

So in config.toml I changed it to XML:

home = [ "HTML", "XML" ]

suffix = ""
delimiter = ""

mediatype = "application/xml"
baseName = "rss"

And then the template is simply called list.xml under /layouts/_default

Mission accomplished. And the custom RSS feed validates at w3c.

One minor issue that I have is that Hugo’s default RSS is rendered as HTML in Firefox with the following encoding declaration appended to it. <?xml version="1.0" encoding="utf-8" standalone="yes" ?>

This doesn’t happen with my Custom RSS Output Format. When I view it in the browser (namely Firefox) it is wrapped in <pre> tags and displayed as code not HTML. But in Feed Readers the Custom RSS is displayed properly. I’ll live with this. Who reads RSS feeds from the browser in 2017 anyway?

So that’s all there is to it for anyone who needs a custom RSS URI when migrating a site to Hugo.

No I will not live with the missing xml declaration in my custom RSS feed!

Naturally Go Templates showed its ugly teeth once again.

As soon as I included <?xml version="1.0" encoding="utf-8" standalone="yes" ?> in my list.xml the first charset “<” became “&lt ;”, and made the XML unreadable. Exactly as reported over here: https://stackoverflow.com/questions/32333279/golang-template-escape-first-char

I was having none of this weirdness, so Hugo Template Functions to the rescue!

Simply made a partial called declaration.html its contents are just the xml declaration from above.

And then in my list.xml I called it like this:
{{ partial "declaration" . | htmlUnescape | safeHTML }}

Now the Custom RSS renders as HTML in Firefox! Identical to Hugo’s default RSS.

(I feel like I’m on my way to becoming a Hugo guru) :nerd_face:

1 Like