Skip to content

The proposition of change to RSS in a multilingual environment #10931

Open
@idarek

Description

@idarek

I would like to propose some changes to how RSS feeds (index.xml) are generated in Hugo.

Firstly, I will start with a reference to sitemap.xml files which point me to change in RSS

When using Hugo in a multilingual environment, the sitemaps are generated a bit differently.

Let's work on my example when I got my Polish site (/) and English (/en/).

In the root directory, there is sitemap.xml file which is not a sitemap but sitemap index file pointing to sitemaps located in language-specific folders /pl/sitemap.xml and /en/sitemap.xml.

That behaviour is great and been thinking if is possible to do implementation in the same manner for RSS.

Currently, for the main language the RSS feed generates a file in the root directory /index.xml for the default language and /en/index.xml for the additional language.

Proposition 1

Let's generate RSS index.xml files language-specific in its language-specific folder like /pl/index.xml and /en/index.xml and /index.xml files in the root folder that will point to different feeds.

In such an example, if somebody will try to search for an RSS feed, for example in Feedly, by typing the site address, it will be displayed with 2 feeds to choose from (the Polish and the English in my example).

Unsure if there is behaviour like sitemapindex, but I saw some websites, where I search for RSS by main URL I was presented with multiple suggestions/feeds to subscribe to (to choose from).

Example:

If you try to add a Feed in Feedly from https://www.macworld.com/ you will be presented with multiple options

This is because their website head contains multiple references to RSS feeds > See Proposition 1B

Implication

This approach has its implication, however. If people got our site added to RSS already, their feeds will stop working (updating).

Proposition 1B (temporary solution)

In reference to the above behaviour from macworld website, to return (suggest) all feeds to choose from when searching through the main (baseURL) address for a feed.

If the case of macworld is putting multiple feeds (as an output to .OutputFormats.Get "rss" when .Translations) when visiting the default language, this can be achieved without problems and changes.

My temporary solution:

  {{- 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 }}

Proposition 2 - All in One approach (preferred)

Let's generate RSS index.xml files language-specific in its language-specific folder like /pl/index.xml and /en/index.xml and in the root folder generate /index.xml that will be a file that contains combined feeds from both languages.

As discussed here https://discourse.gohugo.io/t/multilingual-rss-feed/16689/4

Homepage to contain

<link rel="alternate" type="application/rss+xml" href="https://example.com/index.xml" title="Combined RSS (PL+EN)">
<link rel="alternate" type="application/rss+xml" href="https://example.com/pl/index.xml" title="PL RSS">
<link rel="alternate" type="application/rss+xml" href="https://example.com/en/index.xml" title="EN RSS">

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions