This post will be very short and precise. In Jekyll, we had to create an .xml file using liquid templates to tell Jekyll that we want an rss.xml
or similarly sitemap.xml
. Luckily, Hugo creates these files for us under the hood. You can check them by going to /index.xml
and /sitemap.xml
pages in your Hugo website. Hugo even creates “index.xml” for sections and taxonomies.
However, you may want to overwrite the default RSS template because it’ll include only the pages directly under your root (/content
) folder and it’ll include pages like about.md
. To overwrite the default RSS template, you need to copy the original template into /layouts/_default/
and name it as index.rss.xml
.
Then you need to, change how it loops over {{ range $pages }}
. This is how I set $pages to include all sub-folders (sections as Hugo called them) and exclude ordinary pages like “about page”.
{{- $pages := where $.Site.RegularPages ".Type" "!=" "ordinary" -}}
Done!
One last thing, if you name the file as /layouts/_default/rss.xml
, then it will affect all RSS files including section RSS, taxonomy RSS. For example, let’s say I have a section called “blog” then Hugo will generate an RSS feed at /blog/index.xml
. This is the default behavior. If we name the file as rss.xml
instead of index.rss.xml
Hugo will apply our template not only on /index.xml
but also /blog/index.xml
which is not what I want. See, RSS Template Lookup Order from Hugo docs.