I made some changes to the main rss template to add two requirements.
- show title + subtitle within
- always include the header image at the start of the post item
- filter out content that has “Params.options.unlisted” set to true
I first placed the code within layouts/rss.xml
and noticed that the feeds for taxonomy were still using the internal template. Or at least they were still showing unlisted content.
So I copied the template to
- layouts/_default/section.rss.xml
- layouts/_default/taxonomy.rss.xml
- layouts/_default/terms.rss.xml
From what I saw in the internal template, the file at layouts/rss.xml should also work for taxonomies and terms.
Is the code wrong or am I wrong in where I’m placing the template file? I’d like to avoid duplicating the template.
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ .Site.Title }} by {{ .Site.Params.author }}</title>
<link>{{ .Permalink }}</link>
<description>{{ .Site.Params.subtitle }}</description>
<generator>Hugo - gohugo.io</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>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
<image>
<url>{{ .Site.Params.logo | absURL }}</url>
<title>{{ .Site.Title }}</title>
<link>{{ .Permalink }}</link>
</image>
{{ with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{ end }}
{{- $pctx := . }}
{{- if .IsHome }}{{ $pctx = .Site }}{{ end }}
{{- $pages := slice }}
{{- if or $.IsHome $.IsSection }}
{{- $pages = $pctx.RegularPages }}
{{- else }}
{{- $pages = $pctx.Pages }}
{{- end }}
{{- $limit := .Site.Config.Services.RSS.Limit }}
{{/* New condition: Filter pages where .Params.options.unlisted is not true */}}
{{- $pages = where $pages "Params.options.unlisted" "!=" true }}
{{ range first $limit $pages }}
<item>
<title>{{ .Title }} {{.Params.subtitle}}</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>
{{ $img := (.Resources.ByType "image").GetMatch "*header*" }}
{{ with $img }}
{{ $img := .Resize "640x" }}
{{ printf "<![CDATA[<img src=\"%s\" width=\"%d\" height=\"%d\"/>]]>" $img.Permalink $img.Width $img.Height | safeHTML }}
{{ end }}
{{ .Content | html }}
</description>
</item>
{{ end }}
</channel>
</rss>