Adding output format with custom file name


I am trying to have my Atom feed generated under a file named feed.atom, similar to index.xml (which I successfully renamed to feed.rss, it that matters).

What I did:

  1. Add media type to config.toml:
        suffixes = ["atom"]
  1. Add output format to config.toml:
        mediaType = "application/atom+xml"
        baseName = "feed"
        rel = "alternate"
        isHTML = false
        isPlainText = false
        noUgly = true
        permalinkable = false

Finally I was creating my template file under /layouts/_default/index.atom.

Result: The feed files for home taxonomy is generated as expected, other taxonomies still miss their files :frowning:
I can also see in the console that there are quite some warnings:

WARN 2019/08/05 14:01:44 found no layout file for "atom" for "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2019/08/05 14:01:44 found no layout file for "atom" for "section": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

I know it has something to do with Hugo’s lookup orders and I tried lots of combinations according to the documentation. It seems I still don’t get it :expressionless:

Is anybody willing to give me a hint that would guide me into the right direction?

Many thanks,

You need to set the outputs in your site’s config.toml for all the page kinds where you want the Atom feed. Here’s an example:

  # <domain>/atom.xml
  home = ["HTML", "RSS", "ATOM"]     # default = ["HTML", "RSS"]
  # <domain>/posts/atom.xml
  section = ["HTML", "RSS", "ATOM"]  # default = ["HTML", "RSS"]
  # <domain>/tags/mytag/atom.xml, <domain>/categories/mycat/atom.xml
  taxonomy = ["HTML", "RSS", "ATOM"] # default = ["HTML", "RSS"]



Thanks! It was too abvious to me it seems that I forgot to mention that I did that as well.
If that wasn’t the case, none of the warnings would appear and also the public/feed.atom file would not be generated already.

Any idea how to resolve the warnings to that Hugo can find the template file to generate the files also for sections and taxonomy nodes?

Oh, and I wrote my very own Atom template and did not use the template file you linked. (yours also implies to use the default file name index.xml, not feed.atom which is what I want).

No, I am using atom.xml and setting the template in index.atom.xml.

Try changing your template file name to index.atom.atom in the _default directory.

I tried to name it index.atom.atom but it wasn’t successful.

A working combination I just found seems to be list.atom, not sure why the index name wouldn’t work…

hmm, and index.atom also didn’t work?

Ensure that you do not have multiple .atom files in the layouts, else based on the page kind, one will have precedence over the other.

Nope, index.atom didn’t work either. It actually sounds like a bug to me… (for the record, using Hugo v0.56.3).

There is only one single file using extension .atom and that’s my list.atom file right now.

If I simply change the file suffix back to “xml”, then feed.xml will start to work. You could think that also feed.atom must work but it doesn’t. It seems to me when you are not working with one of the common suffixes, it is not behaving as expected.

It very well could be. Note that something related to casing of the output format name was fixed in Hugo master branch in (if you build from master, see if that helps).

It’s not! I completely didn’t pay attention to what I was typing… for templates:

  • index.* applies only to home kind pages
  • list.* applies to all kinds (including home) but the single pages (page kind)
  • single.* applies to only the single pages (page kind)

About the Page Kinds, see:

1 Like