Refactored Telegram

It’s all just ones and zeros under the cover

Posts Only RSS Feed in Hugo

This blog is a static website generated using Hugo. Like most other static website generators, Hugo provides a lot of features out of the box, one of them being the generation of RSS feeds. I wanted to add a link to an RSS feed of the blog posts to the nav-bar. After trying the /index.xml, I noticed that it included entries for the static pages that are not themselves posts, like the About page.

I wanted to exclude these static pages them from the RSS feed. Here is how I did it.

First, do not do what I was considering and change the RSS feed template itself. This is unnecessary and will leave you needing to maintain the template going forward. Fortunately RSS is a relatively stable format now, but you will need to stay up to date with how Hugo templates work, which will just distract you from writing content1. Also, it is unnecessary, as we shall see below.

As is considered standard for a Hugo sites, all the posts that make up the blog are located in a content/posts directory, while other directories exist for all the other non-post pages of the site. Here is the tree output of how this site is organised:

content
├── about
│   └── index.md
└── posts
	├── hello-world.md
	└── rss-in-hugo.md

Hugo will generate a RSS feed for each section at /<section>/index.xml. Usually a section is indicated by the presence of an _index.md file, however Hugo will also consider the first-level directories under content as sections as well.

This means that if your blog posts are located in content/posts, Hugo will generate an RSS feed for those posts, and only those posts, at /posts/index.xml. This is also true if you use a separate directory from posts or if you want RSS feeds for other sections of the site.

One final thing, the RSS title may be something like “Posts at Your Site”, which might be slightly annoying to those subscribing to your RSS feed. I have not yet found a way to change this but when I do, that will probably be another blog post down the line.


  1. Take it from someone who is easily distracted from writing content. ↩︎