published on 05.08.2020

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”.

1
{{- $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.

You are reading the 5th of 19 episodes in Hugo.
Published on 05.08.2020 by Mert Bakır with commit 3a172e2.
hugo
#hugo #rss #web-dev
Next episode:
Sitemap & Robots & NoIndex NoFollow
published on 06.08.2020

Search engine bots or crawlers, use two files to crawl a website more intelligently. These are robots.txt and sitemap.xml. A robots.txt file tells search engine crawlers which pages or files the crawler can or can’t request from the site. This is used mainly to avoid overloading your site with …

published on 21.08.2020

Math typesetting, or rendering LaTeX, in Hugo is not a hard task. We have two popular alternatives. First one is mathjax, I was using it before with jekyll. The other popular library for math typesetting is KaTeX. Since it’s is faster, this time I’ll go with KaTeX. Implementing these …

published on 22.08.2020

Tags in Hugo is a default taxonomy and we don’t need any special configuration to use tags. We just enter the tags in the post’s front-matter. This can be YAML, TOML, or JSON. I’m using the YAML format, just a personal preference. […] 1 tags:["hugo","tags"] …

published on 24.01.2021
edited on 11.06.2021

Some time ago, I wanted to display image galleries on my Hugo website and searched for Hugo themes for photography and gallery. I can’t say I find much. Then, I met with a javascript library called nanogallery2 which is using another javascript library as an image viewer lightbox2. In this …

published on 23.01.2021
edited on 11.06.2021

Image processing may seem complicated at first but it’s actually easy and definitely worth implementing since it’ll help you decrease page load times. As you probably know, we don’t want to load raw images with huge sizes for small thumbnails or blog-posts. We want to load a small …

published on 29.11.2020
edited on 05.12.2020

Plotly is a visualization library that allows us to write code in Python, R, or Julia and generates interactive graphs using Javascript. So, we don’t have to deal with Javascript. You can checkout Plotly gallery, there are interesting works. Anyway, last week, I’ve started learning …

published on 18.09.2020
edited on 13.02.2021

First of all, if you don’t know about data files, you may want to start reading from data files in hugo. This post is about a solution for a very particular problem. How can we use “group by” for the data from data files? Let me clarify with an example. I was creating a single page …