· 2 minute read

Hugo’s default RSS template publishes an unlimited number of items and shows a summary rather than full content. Also, the feed URL and the content Hugo generates vary depending on the active page’s content type – post, page, section, category or tag.

For this site, I’ve published one RSS feed with the following attributes:

  • full content so that readers don’t have to leave their RSS client
  • most recent 15 posts in the /blog directory
  • my name as the feed title
  • a descriptive URL /feed.xml

To create a similar feed for your Hugo site, follow these steps:

  1. Create a new file in your theme directory at /layouts/_default/rss.xml.

  2. Copy the Hugo RSS template and paste it in rss.xml.

  3. In my site’s config file, I declare my name in the author parameter. To use the same parameter as the feed title, in rss.xml change the feed’s <title> tag to:

      <title>{{ $.Site.Params.author }}</title>
    1. For consistency with the feed title, simplify the channel’s <description>:
      <description>Recent blog posts by {{ $.Site.Params.author }}</description>
  4. By default, Hugo publishes all items in the feed:

    {{ range .Data.Pages }}

    To show the most recent 15 items and to constrain items to those in one directory – for example, /blog – change the range to:

    {{ range first 15 (where .Data.Pages "Section" "blog") }}
  5. To show the item’s full content in the feed, change the <item>’s <description> tag to:

      <description>{{ .Content | html }}</description>
    1. Hugo renders the feed at /index.xml by default. You can specify your own URL in your config file – for example, feed:
      home = [ "HTML", "RSS" ]
      mediatype = "application/rss"
      baseName = "feed"

Here’s a preview of the feed in the feedly RSS client:

Recent items shown in feedly
comments powered by Disqus