hugo/content/en/templates/rss.md
Bjørn Erik Pedersen 9aec42c545 Squashed 'docs/' changes from 686c7b6eb..7ef2dbce4
7ef2dbce4 Cleanup RSS templates page
0e23d5e1a Fix multilingual permalinks example
b3c342b07 Update faq.md
f73109ae2 Regen CLI docs
ac6ee2027 Fix minor nitpicks (#2233)
f24fcffe1 Mention the Giscus comments system (#2234)
418fa981e Remove reference to Ghost migration tool
94a76df29 Adjust table layout
e263ad6b9 content: Fix typos
fd1eb26b5 Update featured image in digital.gov showcase
d3d946555 Correct directory description
bbe1dff56 Use sentence case for heading
acfa0be54 Add hosting provider fetch depth to GitInfo variables page
d78c427e6 Fix typo
751517fea Fix spelling mistake
cdd77aa9a Update content for v0.118.0
c77d09b1c Format netlify.toml
d5a6c4f51 netlify: Hugo 0.118.1
8c717301a Revert "netlify: Hugo 0.118.0"
a9b2ef5c2 netlify: Hugo 0.118.0
61959591c Merge commit '77b976dd92b4f66657d83d875aef0c617df492d9'
95f2029a1 docs: Regen docs helper
fd57ba960 markup/goldmark: Add CJK extension
2bfb3bf4c docshelper: Improve template lookup order descriptions
b0baa890e cache: Hide IsResourceDir from the exported config
b4b071ea0 docs: Replace docs.json with docs.yaml

git-subtree-dir: docs
git-subtree-split: 7ef2dbce4ad728d32c218761c6cfbe2f58f8da16
2023-09-24 11:54:45 +02:00

91 lines
2.8 KiB
Markdown

---
title: RSS templates
description: Use the built-in RSS template, or create your own.
keywords: [rss, xml, templates]
categories: [templates]
menu:
docs:
parent: templates
weight: 160
weight: 160
toc: true
---
## Configuration
By default, when you build your site, Hugo generates RSS feeds for home, section, taxonomy, and term pages. Control feed generation in your site configuration. For example, to generate feeds for home and section pages, but not for taxonomy and term pages:
{{< code-toggle file=hugo copy=false >}}
[outputs]
home = ['html', 'rss']
section = ['html', 'rss']
taxonomy = ['html']
term = ['html']
{{< /code-toggle >}}
To disable feed generation for all [page kinds]:
{{< code-toggle file=hugo copy=false >}}
disableKinds = ['rss']
{{< /code-toggle >}}
By default, the number of items in each feed is unlimited. Change this as needed in your site configuration:
{{< code-toggle file=hugo copy=false >}}
[services.rss]
limit = 42
{{< /code-toggle >}}
Set `limit` to `-1` to generate an unlimited number of items per feed.
The built-in RSS template will render the following values, if present, from your site configuration:
{{< code-toggle file=hugo copy=false >}}
copyright = '© 2023 ABC Widgets, Inc.'
[author]
name = 'John Doe'
email = 'jdoe@example.org'
{{< /code-toggle >}}
## Include feed reference
To include a feed reference in the `head` element of your rendered pages, place this within the `head` element of your templates:
```go-html-template
{{ with .OutputFormats.Get "rss" -}}
{{ printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink site.Title | safeHTML }}
{{ end }}
```
Hugo will render this to:
```html
<link rel="alternate" type="application/rss+xml" href="https://example.org/index.xml" title="ABC Widgets">
```
## Custom templates
Override Hugo's [built-in RSS template] by creating one or more of your own, following the naming conventions as shown in the [template lookup order table].
For example, to use different templates for home, section, taxonomy, and term pages:
```text
layouts/
└── _default/
├── home.rss.xml
├── section.rss.xml
├── taxonomy.rss.xml
└── term.rss.xml
```
RSS templates receive the `.Page` and `.Site` objects in context.
[built-in RSS template]: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml
[page kinds]: /getting-started/glossary/#page-kind
[template lookup order table]: #template-lookup-order
## Template lookup order
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" >}}