Skip to content

Instantly share code, notes, and snippets.

@rogeriopradoj
Forked from lpar/README.md
Created December 21, 2017 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeriopradoj/4c6d19f83241e0db48880ae12cb37ac5 to your computer and use it in GitHub Desktop.
Save rogeriopradoj/4c6d19f83241e0db48880ae12cb37ac5 to your computer and use it in GitHub Desktop.
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:
    [mediaTypes]
    [mediaTypes."application/atom"]
    suffix = "xml"

    [outputFormats.Atom]
    mediaType = "application/atom"
    baseName = "index"
    isPlainText = false
  1. Tell Hugo to produce the home page in Atom and HTML formats, also in config.toml:
    [outputs]
    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="http://www.w3.org/2005/Atom">
<title>{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}</title>
<link rel="self" href="{{ .Permalink }}"/>
<updated>{{ .Date.Format "2006-01-02T15:04:05-0700" | safeHTML }}</updated>
<author>
<name>YOUR NAME HERE</name>
<email>YOUR EMAIL ADDRESS</email>
<uri>DEFINITIVE URI OF YOUR WEB SITE</uri>
</author>
<id>{{ .Permalink }}</id>
{{ range first 15 .Data.Pages }}
<entry>
<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>
</entry>
{{ end }}
</feed>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment