RSS feed only for blog posts

I’m building a site with two sections, one is a “blog” and another one is “projects”. Also blog posts use taxonomy (categories and tags). I want to create the RSS feed for blog, but not for projects or any other pages

According to the docs, by default Hugo generates RSS feeds for home, section, taxonomy, and term pages. So I changed my hugo.toml as show below to disable RSS on all pages, except sections.

[outputs]
home = ["html"]
section = ["html", "rss"]
taxonomy = ["html"]
term = ["html"]

But this still gives me RSS for projects section. As I understand, I have to use custom RSS template to collect only pages from the “blog” section of the site. But it seems that even with custom template Hugo creates an empty feed for “projects”.

Here is my custom RSS template, basically it is a sligtly modified built-in template

{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = (where (where $pctx.RegularPages ".Section" "blog") "Kind" "page")  -}}
{{- else -}}
{{- $pages = (where (where $pctx.Pages ".Section" "blog") "Kind" "page")  -}}
{{- end -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- 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>{{ 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 }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>{{ site.Language.LanguageCode }}</language>{{ 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>{{ .Date.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 $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>
      <description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
    </item>
    {{ end }}
  </channel>
</rss>

Am I missing something? Is it possible to completely avoid generating RSS for “projects” section or what I have done already is the best possible solution?

Disable the RSS output format for all page kinds in your site configuration:

[outputs]
home = ['html']
section = ['html']
taxonomy = ['html']
term = ['html']

Then enable the RSS output format for the blog section:

content/blog/_index.md

+++
title = 'Blog'
outputs = ['html','rss']
+++
2 Likes

Thanks a lot! This works exactly as I need.

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