hugo/content/en/templates/rss.md
Bjørn Erik Pedersen 3a44bf182f Squashed 'docs/' changes from 81847981f..d88477eb3
d88477eb3 Fix some more redirect alias loops
209735670 Update features.md
d4ec6ef87 Remove redirect loop from functions/default
ce14da435 Fix the AlternativeOutputFormats/OutputFormats examples
f64a22469 Update cond.md
357a70a32 Remove redirect loop from templates/404
4ad7b01ba Remove some aliases that were causing infinite redirect loops
fd378e66a Fix alias redirect loop
ec3629f6f Revert "Set code background to white"
ffc56b880 Revert "Make inline code gray"
2a964e261 Make inline code gray
44069e09c Set code background to white
d39c790d0 Linked my own blog2md migration script
3e55267be Release 0.46
7b6cfdd8b releaser: Prepare repository for 0.47-DEV
d4cb54806 releaser: Add release notes to /docs for release of 0.46
6518ac7e7 releaser: Bump versions for release of 0.46
e54334d5c Merge commit '766085c2dc6fc95ac30fda2a9ebde2355fc12554'

git-subtree-dir: docs
git-subtree-split: d88477eb3a1959e2764d6025f5aa7a57a4a611e7
2018-08-08 13:54:28 +02:00

5 KiB
Raw Blame History

title linktitle description date publishdate lastmod keywords categories menu weight sections_weight draft toc
RSS Templates RSS Templates Hugo ships with its own RSS 2.0 template that requires almost no configuration, or you can create your own RSS templates. 2017-02-01 2017-02-01 2017-02-01
rss
xml
templates
templates
docs
parent weight
templates 150
150 150 false true

RSS Template Lookup Order

See Template Lookup Order for the complete reference.

{{% note "Hugo Ships with an RSS Template" %}} Hugo ships with its own RSS 2.0 template. The embedded template will be sufficient for most use cases. {{% /note %}}

RSS pages are of the type Page and have all the page variables available to use in the templates.

Section RSS

A sections RSS will be rendered at /<SECTION>/index.xml (e.g., http://spf13.com/project/index.xml).

Hugo provides the ability for you to define any RSS type you wish and can have different RSS files for each section and taxonomy.

Lookup Order for RSS Templates

The table below shows the RSS template lookup order for the different page kinds. The first listing shows the lookup order when running with a theme (demoTheme).

{{< datatable-filtered "output" "layouts" "OutputFormat == RSS" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}

Configure RSS

By default, Hugo will create an unlimited number of RSS entries. You can limit the number of articles included in the built-in RSS templates by assigning a numeric value to rssLimit: field in your project's config file.

The following values will also be included in the RSS output if specified in your sites configuration:

languageCode = "en-us"
copyright = "This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License."

[author]
    name = "My Name Here"

The Embedded rss.xml

This is the default RSS template that ships with Hugo. It adheres to the RSS 2.0 Specification.

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <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 -- 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 .Pages }}
    <item>
      <title>{{ .Title }}</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>{{ .Summary | html }}</description>
    </item>
    {{ end }}
  </channel>
</rss>

{{% warning "XML Header" %}} Hugo will automatically add the following header line to this file on render. Please do not include this in the template as it's not valid HTML.

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>

{{% /warning %}}

Reference your RSS Feed in <head>

In your header.html template, you can specify your RSS feed in your <head></head> tag using Hugo's Output Formats like this:

{{ range .AlternativeOutputFormats -}}
    {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{ end -}}

If you only want the RSS link, you can query the formats:

{{ with .OutputFormats.Get "rss" -}}
    {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{ end -}}

Either of the two snippets above will generate the below link tag on the site homepage for RSS output:

<link rel="alternate" type="application/rss+xml" href="https://example.com/index.xml" title="Site Title">

We are assuming BaseURL to be https://example.com/ and $.Site.Title to be "Site Title" in this example.