Alternative RSS/ATOM feed template

Having just swapped some messages with @kaushalmodi in another post about RSS feeds, I thought that I ought to share my own RSS/ATOM template for ridicule by all:

{{/***
   * Override the Hugo RSS feed default as that only shows a summary of the post, 
   * not the whole article which is what most people really want.
   * Includes the page .Description as well as the .Content as this typically
   * contains different text.
   ***/}}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ if eq  .Title  .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
    <link>{{ .Permalink }}</link>
    <description>
      Recent content {{ if ne  .Title  .Site.Title }}{{ with .Title }}about {{.}} {{ end }}{{ end }}from {{ .Site.Title }} | 
      {{ with $.Site.Params.Description }}{{ . }}{{ end }}
    </description>
    <generator>Hugo | gohugo.io | Theme twenty-sixteen</generator>
    {{- with .Site.LanguageCode -}}<language>{{.}}</language>{{end}}
    {{- with .Site.Author.email -}}<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}
    {{- with .Site.Author.email -}}<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}
    {{- with .Site.Copyright -}}<copyright>{{.}}</copyright>{{end}}
    {{- if not .Date.IsZero -}}<lastBuildDate>{{ now.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
    {{ with .OutputFormats.Get "RSS" }}
        {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
    {{ end }}
    {{ range .Data.Pages }}
    <item>
      <title>{{ .Title }}</title>
      <link>{{ .Permalink }}</link>
      <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
      {{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
      <guid>{{ .Permalink }}</guid>
      {{/* JK: 2018-04-08 Change .Summary to .Content to get full text */}}
      {{/* JK: 2018-05-08 Add .description to content */}}
      <description><div>{{ .Description | html }}</div><div>{{ .Content | html }}</div></description>
      {{/* JK: 2018-04-08 Add post author */}}
      <author>{{ .Params.Author | default .Site.Params.author }}</author>
      {{- range .Params.categories -}}{{/* JK: 2018-04-08 Add category list */}}
      <category domain="{{ $.Site.BaseURL }}/categories/{{ . | urlize }}">{{ .}}</category>
      {{ end }}
    </item>
    {{ end }}
  </channel>
</rss>

I have this in layouts/_default/rss.xml in the twenty-sixteen theme that I’m using on my blog.

It is a copy of the template from the Hugo Docs with amendments as documented in the code comments.

Note that I use the page description meta visibly at the top of the page so the content is complementary to it which is why I want it to also appear in the feed. I will probably make this optional in the theme when I get round to it.

2 Likes

That is RSS feed only. The ATOM feed would be a different output format.

Thanks for sharing that snippet; I have now added category tags to my RSS and ATOM feeds too.

Your post threw me down a rabbit hole to finally make the RSS feed on my site valid… things I need to do to make that happen :stuck_out_tongue:

But finally both of my feeds are valid! RSS | ATOM


Will now leave the fixing of those warnings for some other day.

Thanks.

I’ve debated whether to do a separate ATOM feed but as far as I can tell, it is of little worth since all the relevant tools will consume both anyway.

But I’d be happy to be convinced otherwise - perhaps there is some additional value in an ATOM feed? Should I be using ATOM tags rather than RSS ones?

By the way, I use tags as well as categories in my posts. As RSS doesn’t understand tags, I’ve now included them as RSS categories by duplicating the appropriate loop.

Well ATOM is used by a service like Bridgy Fed so that your site can interact with federated social networks like Mastodon and Hubzilla.

Beyond that there is really no practical difference in the consumption of RSS and ATOM by the various feed readers.

2 Likes

Thanks. I’m really not into all that yet so I’ll not worry about it for now.

Without wishing to seem rude to those who are into that scene, it is like taking a step back into the 70’s and 80’s when reading about the “indiweb”. Massive techno-babble and little clarity. Just like in the days of FIDOnet :smile:

Sorry, showing my age now. But honestly, the whole thing would benefit greatly from the use of simplified language and simpler tools.

I found a good page about the VS

http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared

3rd version could be JSON, I posted it here

Hugo can do it all! For feeds I like inoreader, he can use RSS, ATOM and JSON