Skip to content

Instantly share code, notes, and snippets.



Last active Oct 9, 2020
What would you like to do?
How to make Hugo (0.20+) generate an Atom feed instead of RSS

The Hugo static site generator sadly still uses the obsolete and badly standardized RSS format.

Here's how to set it up to generate an Atom feed instead. Pretty much all feed readers which understand RSS also understand Atom, except iTunes, and Atom is a better format.

  1. Define an appropriate media type and corresponding output format in config.toml:
    suffix = "xml"

    mediaType = "application/atom"
    baseName = "index"
    isPlainText = false
  1. Tell Hugo to produce the home page in Atom and HTML formats, also in config.toml:
    home = [ "HTML", "Atom" ]
  1. Put an index.atom.xml template file in your layouts directory. You can use the attached one as a starting point, don't forget to edit the author element appropriately or make it take the values from your config.
<feed xmlns="">
<title>{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}</title>
<link rel="self" href="{{ .Permalink }}"/>
<updated>{{ .Date.Format "2006-01-02T15:04:05-0700" | safeHTML }}</updated>
<name>YOUR NAME HERE</name>
<email>YOUR EMAIL ADDRESS</email>
<id>{{ .Permalink }}</id>
{{ range first 15 .Data.Pages }}
<title>{{ .Title }}</title>
<link rel="alternate" href="{{ .Permalink }}"/>
<id>{{ .Permalink }}</id>
<published>{{ .Date.Format "2006-01-02T15:04:05-0700" | safeHTML }}</published>
<updated>{{ .Lastmod.Format "2006-01-02T15:04:05-0700" | safeHTML }}</updated>
<summary>{{ .Summary | html }}</summary>
{{ end }}

This comment has been minimized.

Copy link

@adiabatic adiabatic commented May 18, 2017

The media-type stuff helped. Thanks!


This comment has been minimized.

Copy link

@marcisme marcisme commented Jul 2, 2017

Thanks for this. The configuration was helpful. I had to make some adjustments to the template to get it to validate.

<feed xmlns="">
  <title>{{ if eq  .Title  .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
  <link href="{{ .Permalink }}index.xml" rel="self"/>
  <link href="{{ .Permalink }}"/>{{ if not .Date.IsZero }}
  <updated>{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>{{ end }}
  <id>{{ .Permalink }}</id>{{ with }}
    <name>{{.}}</name>{{ with $ }}
  <generator>Hugo --</generator>{{ range .Data.Pages }}
    {{ `<title type="html"><![CDATA[` | safeHTML }}{{ .Title }}]]></title>
    <link href="{{ .Permalink }}"/>
    <id>{{ .Permalink }}</id>{{ with .Site.Params.Author }}
    <published>{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</published>
    <updated>{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>
    {{ `<content type="html"><![CDATA[` | safeHTML }}{{ .Content }}]]></content>
  </entry>{{ end }}

Update: I removed the | html part from {{ .Content | html }} because escaping the content caused it to not render properly in my feed reader. The validators complain about the data-lang attributes that are there for syntax highlighting, but I think that's ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment