mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
07b8d9466d
fb551cc75 Update index.md 7af894857 Update index.md d235753ea Hugo 0.82.1 e03e72deb Merge branch 'temp0821' e62648961 Merge branch 'release-0.82.1' e1ab0f6eb releaser: Add release notes to /docs for release of 0.82.1 5d354c38d Replaced ``` code blocks with Code Toggler c9d065c20 Remove duplicate YAML keys (#1420) 8ae31e701 Add webp image encoding support 848f2af26 Update internal.md (#1407) c103a86a4 Fix `ref` shortcode example output (#1409) 9f8ba56dc Remove leading dot from where function KEY (#1419) 363251a51 Improve presentation of template lookup order (#1382) b73da986d Improve description of Page Resources (#1381) 4e0bb96d5 Rework robots.txt page (#1405) edf893e6f Update migrations.md (#1412) 450f1580b Add link to `site` function doc (#1417) cfffa6e6f Added one extension to the list (#1414) 05f1665a0 Update theme 5de0b1c6a Update theme 250e20552 Add hugo.IsExtended dea5e1fd7 Fix typo on merge function page (#1408) 1bbed2cf3 Update configuration.md be0b64a46 Omit ISO cbb5b8367 Fix `dateFormat` documentation 698f15466 Regenerate the docshelper f9a8a7cb6 Update multilingual.md a22dc6267 Fix grammar (#1398) eb98b0997 Fix pretty URL example (#1397) f4c4153dc Mention date var complementation in post scheduling (#1396) 17fae284c Fix resources.ExecuteAsTemplate argument order (#1394) 97e2c2abb Use code-toggle shortcode in `multilingual.md` (#1388) 3a84929bb Harmonize capitalization (#1393) 17f15daa6 fix file naming used in example (#1392) 5d97b6a18 Add slice syntax to sections permalinks config 00665b97b Improve description of `site.md` edcf5e3fc Fix example in `merge.md` f275ab778 Update postprocess.md 9593e3991 Fix file name 59bd9656f Update postprocess.md 1172fb6d0 Update to theNewDynamic repository (#1263) f5b5c1d2c Update Hugo container image 4f2e92f2a Adapt anchorize.md to Goldmark 98aa19073 Directly link to `highlight` shortcode (#1384) 4c75c2422 Fix header level f15c06f23 markdownify: add note about render-hooks and .RenderString (#1281) 69c82eb68 Remove Blackfriday reference from shortcode desc (#1380) 36de478df Update description of ignoreFiles config setting (#1377) 6337699d8 Remove "Authors" page from documentation (#1371) 35e73ca90 fix indent in example (#1372) d3f01f19a Remove opening body tag from header example (#1376) 341a5a7d8 Update index.md c9bfdbee6 Release 0.82.0 119644949 releaser: Add release notes to /docs for release of 0.82.0 32efaed78 docs: Regenerate docs helper dea5449a2 docs: Regen CLI docs eeab18fce Merge commit '81689af79901f0cdaff765cda6322dd4a9a7ccb3' d508a1259 Attributes for code fences should be placed after the lang indicator only c80905cef deps: Update to esbuild v0.9.0 95350eb79 Add support for Google Analytics v4 02d36f9bc Allow markdown attribute lists to be used in title render hooks 7df220a64 Merge commit '9d31f650da964a52f05fc27b7fb99cf3e09778cf' d80bf61b7 Fixes #7698. git-subtree-dir: docs git-subtree-split: fb551cc750faa83a1493b0e0d0898cd98ab74465
92 lines
3.4 KiB
Markdown
92 lines
3.4 KiB
Markdown
---
|
||
title: RSS Templates
|
||
linktitle: RSS Templates
|
||
description: Hugo ships with its own RSS 2.0 template that requires almost no configuration, or you can create your own RSS templates.
|
||
date: 2017-02-01
|
||
publishdate: 2017-02-01
|
||
lastmod: 2017-02-01
|
||
keywords: [rss, xml, templates]
|
||
categories: [templates]
|
||
menu:
|
||
docs:
|
||
parent: "templates"
|
||
weight: 150
|
||
weight: 150
|
||
sections_weight: 150
|
||
draft: false
|
||
toc: true
|
||
---
|
||
|
||
## RSS Template Lookup Order
|
||
|
||
See [Template Lookup Order](/templates/lookup-order/) for the complete reference.
|
||
|
||
{{% note "Hugo Ships with an RSS Template" %}}
|
||
Hugo ships with its own [RSS 2.0 template](#the-embedded-rssxml). The embedded template will be sufficient for most use cases.
|
||
{{% /note %}}
|
||
|
||
RSS pages are of the type `Page` and have all the [page variables](/variables/page/) available to use in the templates.
|
||
|
||
### Section RSS
|
||
|
||
A [section’s][section] RSS will be rendered at `/<SECTION>/index.xml` (e.g., [https://spf13.com/project/index.xml](https://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][config].
|
||
|
||
The following values will also be included in the RSS output if specified:
|
||
|
||
{{< code-toggle file="config" >}}
|
||
languageCode = "en-us"
|
||
copyright = "This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License."
|
||
|
||
[author]
|
||
name = "My Name Here"
|
||
{{< /code-toggle >}}
|
||
|
||
## The Embedded rss.xml
|
||
|
||
This is the default RSS template that ships with Hugo:
|
||
|
||
https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml
|
||
|
||
## 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][Output Formats] like this:
|
||
|
||
```go-html-template
|
||
{{ 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:
|
||
|
||
```go-html-template
|
||
{{ 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:
|
||
|
||
```html
|
||
<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._
|
||
|
||
[config]: /getting-started/configuration/
|
||
[embedded]: #the-embedded-rss-xml
|
||
[RSS 2.0]: https://cyber.harvard.edu/rss/rss.html "RSS 2.0 Specification"
|
||
[section]: /content-management/sections/
|
||
[Output Formats]: /templates/output-formats/#link-to-output-formats
|