MediaTypes: how to choose which suffix

For one project, I need an xml feed to live at /feed.rss instead of /index.xml. Now I tried adding the rss suffix to the application/rss+xml mediaType before using it on my custom output format.

    - xml
    - rss

    mediaType: application/rss+xml
    baseName: feed

Now how can I have the file generated at /feed.rss instead of /feed.xml. I tried using a layout called index.rss_feed.rss but it is not being picked up (the output format file is not created)

Any ideas?

Thanks a ton!


The following emits both feed.rss and index.xml for me:


suffixes = ["rss","xml"]

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


mediaType = "application/rss+xml"
baseName = "feed"
notAlternatives = true

copied from internal Hugo template


{{- $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 -}}
{{- 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="">
    <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 --</generator>{{ with .Site.LanguageCode }}
    <language>{{.}}</language>{{end}}{{ with }}
    <managingEditor>{{.}}{{ with $ }} ({{.}}){{end}}</managingEditor>{{end}}{{ with }}
    <webMaster>{{.}}{{ with $ }} ({{.}}){{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 }}
      <title>{{ .Title }}</title>
      <link>{{ .Permalink }}</link>
      <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
      {{ with }}<author>{{.}}{{ with $ }} ({{.}}){{end}}</author>{{end}}
      <guid>{{ .Permalink }}</guid>
      <description>{{ .Summary | html }}</description>
    {{ end }}


Previous attempts

Do you need both types of RSS files (index.xml and feed.rss)? I think what is happening is the default xml layout is getting picked up first.

EDIT: What happens if you reverse the order of suffixes?

EDIT: Sorry realized you looked at this already after the fact.

Looking at Custom Output Formats | Hugo

The key distinction for Hugo versions 0.20 and newer is that Hugo looks at an output format’s Name and MediaType’s Suffixes when choosing the template used to render a given Page .

I think you will have to create a new template name something like:


1 Like

I think that the only current way to create outputs for different suffix for a given media type is to create multiple media types. We could (and probably should) add a “suffix selector” to output format config …

1 Like

Thank you all for your answers. I created an issue to follow up this discussion: