Combined RSS feed for Terms

Hello everyone, and a happy new year! :slight_smile:

Could please anyone clarify for me whether it is possible to have a unified RSS feed for Terms?

Currently I’m happily using setup described here. It produces RSS feeds for Posts (list.html) and Series (taxonomies.html). However, for grouped Terms (Writing) it only produces a feed for each individual Term, but not a combined feed for all Terms.

Is it at all possible to have a combined RSS feed for Terms?

You can publish an RSS feed containing anything you want, anywhere you want. For example…

content/foo/_index.md

title = 'Something'
outputs = ['rss']
layout = 'terms-combined'
description = 'A list of x with y'

Then create the custom RSS template, something like:

layouts/_default/terms-combined.rss.xml
{{- $pages := where site.RegularPages "Section" "posts" }}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ printf "%s on %s" .Title site.Title }}</title>
    <link>{{ .Permalink }}</link>

    {{- with .Description }}
      <description>{{ . }}</description>
    {{- end }}

    <generator>{{ printf "Hugo v%s" hugo.Version }}</generator>
    <language>{{ site.Language.LanguageCode }}</language>

    {{- with site.Copyright }}
      <copyright>{{ . }}</copyright>
    {{- end }}

    <lastBuildDate>
      {{- (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML -}}
    </lastBuildDate>

    {{- with .OutputFormats.Get "RSS" }}
      {{ printf "<atom:link href=%q rel=%q type=%q />" .Permalink "self" .MediaType.Type | safeHTML }}
    {{- end }}

    {{- range $pages }}
      <item>
        <title>{{ .Title }}</title>
        <link>{{ .Permalink }}</link>
        <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
        <guid>{{ .Permalink }}</guid>

        {{- with .Description }}
          <description>{{ . }}</description>
        {{- end }}

      </item>
    {{- end }}
  </channel>
</rss>

And change the $pages assignment to whatever you want to build the page collection.

Your custom feed will be published to http://example.org/foo/index.xml

3 Likes

Thank you! Is there anything that is not possible with Hugo? :slight_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.