Filename for shortcodes when using custom RSS output format


My goal is - to create a custom RSS feed, that satisfy the requirements of Facebook Instant Articles guide.

I’ve spent tons of time trying to get a “custom” RSS working, but i got it! I ended up with such configuration of config.toml:

home = ["html", "rss", "fb"]
page = ["html", "amp"]

mediaType = "application/rss"
baseName = "fb"

Now i can define my custom RSS via the file located at layouts/_default/list.xml
My custom RSS is available at {SITE_URL}/fb.xml


So far so good. But i need a shortcode to be used when Hugo builds my custom RSS. I need my shortcode <table> to have another template in my custom RSS. So i tried following filenames:

├── table.fb.xml (1st try)
├── table.xml (2nd try)
├── table.fb.html (3rd try)
└── table.html

But Hugo always uses table.html for rendering. Can someone help me to name the shortcode template correctly to be used when the {SITE_URL}/fb.xml is being rendered?

Somebody… please :pray:

Try this:

  • use html file extensions for all shortcode files.
  • don’t use dots (.) as a name delimiter. Use underscores.

Example: table_fb_xml.html

that did not work :disappointed_relieved:

Looking at this again I notice that my last comment was made in haste. I haven’t used the custom output features much, but I’ll take another stab at helping (while trying to avoid setting up a test site)…

What you are wanting to do should be supported. If it’s helpful, you can see our tests for this feature. Based upon those tests, you should be able to use layouts/shortcodes/table.fb.xml for the shortcode.

But your setting the baseName, so maybe you need to be using layouts/_default/fb.xml instead of list.xml.

1 Like

So output formats are my invention, so I should know the internals of this …

Quickly looking at your setup:

mediaType = "application/rss"
baseName = "fb"

Given the above, table.fb.xml shortcode should get chosen before table.html for the fb output format. If you say that that isn’t the case, I would suggest there are something other in play that I don’t see. Could you somehow share the failing source?

Thank you for your feedback. I hope we will get it work.
I have created the Gitlab repo with my sources. Once commited, its being deployed here. So you can check code and the website.

So as you see here, i have table.fb.xml and table.html. The shortcode wraps the content with figure.

Making the problem clear once again: at fb.xml inside the first article from the top I assume to see the figure class xml-table-class but there is html-table-class instead.

OK; I see what’s going on. Whether this behaviour is surprising/could be improved … maybe, but:

home = ["html", "rss", "fb"]
page = ["html"]

Will not render the regular pages as fb, hence when you list them on the home page, there is no fb version to pick, so we choose the default html version.

Changing it to the below will give you the expected output on the home page, but it may not be what you want.

home = ["html", "rss", "fb"]
page = ["html", "fb"]
1 Like

yeeeah! adding “fb” to page outputs worked! thank you so much! :innocent:

since you said that we are talking about your invention… please tell me how should i understand the logic of naming the custom RSS template.
As i have read somewhere in forums, don’t even remember where because i have searched a lot… i should name it as list.xml (see here). And then be able to see my custom RRS at baseURL/fb.xml.
BUT. As docs say, a template should have the name of custom format in it. So i assumed the right name for my custom homepage template would be index.fb.xml. why not?

Because the baseName in the output format definition defaults to index – you have set it to something else, fb. And you have the output format name being the same as the baseName which confuses it further. So a valid (I think from my recollection) layout for your fb format would be: /layouts/fb.fb.xml which should illustrate my point.

Addendum to my last: baseName doesn’t default to index for new definitions, but that is the default value for most of the built-ins (i.e. HTML etc.)

did you mean /layouts/_default/fb.fb.xml? I tried it too. but only /layouts/_default/list.xml worked.

No, I meant what I said, but I’m taking this from memory. You would be better off reading the documentation.

@andrekosak You are missing your single page specifier for the layout you have.

So here is what you need:

First make sure to create your “fb” page type in the config.toml like @bep said.

home = ["html", "rss", "fb"]
page = ["html", "fb"]

Then create the single page template default in _default called single.fb.xml with the same contents of the list.xml

Then you will get the correct fb.xml item content using your shortcode wrapper when you build.

Note: use hugo -v when testing local to see a verbose output