Multilingual rss feed

I’m trying to have the main rss feed located in /index.xml to ouput all the available languages.

So far the code I have is this:

{{ range first 50 (where (where .Data.Pages ".Params.options" "!=" nil) ".Params.options.unlisted" "!=" true)  }}

Only recently did I noticed that localhost/index.xml only returns the default version. If I want the Portuguese content I need to visit localhost/pt/index.xml.

Is it possible to have the following behaviour?

localhost/en/index.xml => English feed
localhost/pt/index.xml => Portuguese Feed
localhost/index.xml => PT + EN feed

If not, how can I include both languages in the range? I thought it was enough to replace .Data with .Site, but I was wrong.

Would try this first

[outputs]
    home                  = [ "HTML", "RSS"]

[outputFormats.RSS]
    MediaType             = "application/rss+xml"
    BaseName              = "index"
    suffix                = "xml"

my own template is _default/home.rss.xml

I have done it the same way for ATOM and JSON

Well I tried but the result is the same. And since part of the content has an unlisted option, I am forced to range over the content in rss.html

looked in my templates

{{ $r1 := where .Site.Pages "PublishDate" "gt" $start }}
{{ $r2 := where .Data.Pages.ByDate.Reverse "Section" "not in" (split .Site.Params.invisibleSections ",") }}
{{ range $r1 | intersect $r2 }}

Could this be an start for you?

1 Like

The trick to get all language pages is to range over .Site.AllRegularPages etc.

4 Likes

yes that works :slight_smile:

.Data.Pages however allows for a more versatile rss feed, per section and category. So I am going to let it as is, mark it as solved and move on.

Hi All,
I have raised a proposal for this and as I try to find a temporary solution, when somebody put main URL into RSS reader (like Feedly) they will be suggested not only for main url RSS feed but also for any translated there, I come out with this:

  {{- with .Site.GetPage "/" }} <!-- Because I want RSS in header on every page -->
    {{ with .OutputFormats.Get "rss" -}}
      {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
    {{ end -}}
    {{ range .Translations }} <!-- If other languages present output RSS for them as well -->
    {{- $titleLang := .Title }}
      {{ with .OutputFormats.Get "rss" -}}
        {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $titleLang | safeHTML }}
      {{ end -}}
    {{ end }}
  {{- end }}

Sharing here in case somebody will not look through GitHub.

For explanation please see the proposal.