I have a bilingual site (Russian being the default one, English being another one, with weights of 1 and 2, respectively), and I want my RSS feed to have content in both languages. So, based on the builtin rss.xml template, mine looks like this:
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = $pctx.RegularPages -}}
{{- if $.IsHome -}}{{ $pages = where $pctx.RegularPages "Type" "in" site.Params.mainSections }}
{{- range .Translations -}}{{- $pages = $pages | lang.Merge (where .Site.RegularPages "Type" "in" site.Params.mainSections) -}}{{- end -}}
{{- else -}}{{- range .Translations -}}{{- $pages = $pages | lang.Merge .RegularPages -}}{{- end -}}
{{- end -}}
{{- else -}}
{{- $pages = $pctx.Pages -}}
{{- range $pctx.Translations -}}{{- $pages = $pages | lang.Merge .Pages -}}{{- end -}}
{{- end -}}
{{- $pages = where $pages "Params.deleted" "!=" true -}}
{{- $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 }}{{default . (T .)}} {{ T "on"}} {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>{{ T "recent_content" }} {{ if ne .Title .Site.Title }}{{ with .Title }}{{ T "in"}} {{default . (T .)}} {{ end }}{{ end }}{{ T "on" }} {{ .Site.Title }}</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 }}
{{- with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{ end }}
{{- range $.Site.Params.websubHub -}}
<atom:link href="{{ . }}" rel="hub" />
{{ end }}
{{ range $pages }}
<item>
<title>{{ with .Title }}{{ . }}{{ else }}{{ with .Params.like_of }}{{ . }}{{ else }}{{ with .Params.reply_to }}{{ if gt (len .) 0 }}{{ index . 0 }}{{ else }}...{{ end }}{{ end }}{{ end }}{{ end }}</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>{{ .Content | html }}</description>
</item>
{{ end }}
</channel>
</rss>
It seems to work perfectly for all the cases other than the homepage of the default language. In the index.xml
I get for the Russian homepage (i.e. public/index.xml
) the <description>
tag for the pages “borrowed” from English site (i.e. those that don’t have a Russian translation) is empty.
It does not happen in public/en/index.xml
, it doesn’t happen in sections and taxonomies, only in the main homepage.
Even more puzzling, if I run hugo server
and make an edit to this template, as soon as the site rebuilds I get the /index.xml
I want, with <description>
filled for all the pages. However, as soon as I edit any other file (say, add a new page or edit an old one), it reverts to <description>
being empty for English pages in /index.xml
.
Am I missing something obvious, or is hugo server
's weird behaviour an indication of some bug in Hugo?