github.com/shohhei1126/hugo@v0.42.2-0.20180623210752-3d5928889ad7/docs/content/en/templates/rss.md (about) 1 --- 2 title: RSS Templates 3 linktitle: RSS Templates 4 description: Hugo ships with its own RSS 2.0 template that requires almost no configuration, or you can create your own RSS templates. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-02-01 8 keywords: [rss, xml, templates] 9 categories: [templates] 10 menu: 11 docs: 12 parent: "templates" 13 weight: 150 14 weight: 150 15 sections_weight: 150 16 draft: false 17 aliases: [/templates/rss/] 18 toc: true 19 --- 20 21 ## RSS Template Lookup Order 22 23 See [Template Lookup Order](/templates/lookup-order/) for the complete reference. 24 25 {{% note "Hugo Ships with an RSS Template" %}} 26 Hugo ships with its own [RSS 2.0 template](#the-embedded-rss-xml). The embedded template will be sufficient for most use cases. 27 {{% /note %}} 28 29 RSS pages are of the type `Page` and have all the [page variables](/variables/page/) available to use in the templates. 30 31 ### Section RSS 32 33 A [section’s][section] RSS will be rendered at `/<SECTION>/index.xml` (e.g., http://spf13.com/project/index.xml). 34 35 Hugo provides the ability for you to define any RSS type you wish and can have different RSS files for each section and taxonomy. 36 37 ## Lookup Order for RSS Templates 38 39 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`). 40 41 {{< datatable-filtered "output" "layouts" "OutputFormat == RSS" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}} 42 43 ## Configure RSS 44 45 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]. 46 47 The following values will also be included in the RSS output if specified in your site’s configuration: 48 49 ```toml 50 languageCode = "en-us" 51 copyright = "This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License." 52 53 [author] 54 name = "My Name Here" 55 ``` 56 57 ## The Embedded rss.xml 58 59 This is the default RSS template that ships with Hugo. It adheres to the [RSS 2.0 Specification][RSS 2.0]. 60 61 ```xml 62 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 63 <channel> 64 <title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title> 65 <link>{{ .Permalink }}</link> 66 <description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description> 67 <generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }} 68 <language>{{.}}</language>{{end}}{{ with .Site.Author.email }} 69 <managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }} 70 <webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }} 71 <copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }} 72 <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }} 73 {{ with .OutputFormats.Get "RSS" }} 74 {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }} 75 {{ end }} 76 {{ range .Data.Pages }} 77 <item> 78 <title>{{ .Title }}</title> 79 <link>{{ .Permalink }}</link> 80 <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate> 81 {{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}} 82 <guid>{{ .Permalink }}</guid> 83 <description>{{ .Summary | html }}</description> 84 </item> 85 {{ end }} 86 </channel> 87 </rss> 88 ``` 89 90 {{% warning "XML Header" %}} 91 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. 92 ``` 93 <?xml version="1.0" encoding="utf-8" standalone="yes" ?> 94 ``` 95 {{% /warning %}} 96 97 ## Reference your RSS Feed in `<head>` 98 99 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: 100 101 ```go-html-template 102 {{ range .AlternativeOutputFormats -}} 103 {{ printf `<link rel="%s" type="%s+%s" href="%s" title="%s" />` .Rel .MediaType.Type .MediaType.Suffix .Permalink $.Site.Title | safeHTML }} 104 {{ end -}} 105 ``` 106 107 If you only want the RSS link, you can query the formats: 108 109 ```go-html-template 110 {{ with .OutputFormats.Get "rss" -}} 111 {{ printf `<link rel="%s" type="%s+%s" href="%s" title="%s" />` .Rel .MediaType.Type .MediaType.Suffix .Permalink $.Site.Title | safeHTML }} 112 {{ end -}} 113 ``` 114 115 Either of the two snippets above will generate the below `link` tag on the site homepage for RSS output: 116 117 ```html 118 <link rel="alternate" type="application/rss+xml" href="https://example.com/index.xml" title="Site Title"> 119 ``` 120 121 _We are assuming `BaseURL` to be `https://example.com/` and `$.Site.Title` to be `"Site Title"` in this example._ 122 123 [config]: /getting-started/configuration/ 124 [embedded]: #the-embedded-rss-xml 125 [RSS 2.0]: http://cyber.law.harvard.edu/rss/rss.html "RSS 2.0 Specification" 126 [section]: /content-management/sections/ 127 [Output Formats]: /templates/output-formats/#link-to-output-formats