RSS 模板
配置
默认情况下,当你构建你的站点时,Hugo 会为主页、章节、分类和术语页面生成 RSS 源。在你的站点配置中控制源的生成。例如,要为主页和章节页面生成源,但不为分类和术语页面生成源
hugo。
outputs:
home:
- html
- rss
section:
- html
- rss
taxonomy:
- html
term:
- html
[outputs]
home = ['html', 'rss']
section = ['html', 'rss']
taxonomy = ['html']
term = ['html']
{
"outputs": {
"home": [
"html",
"rss"
],
"section": [
"html",
"rss"
],
"taxonomy": [
"html"
],
"term": [
"html"
]
}
}
要禁用所有 页面类型 的源生成
hugo。
disableKinds:
- rss
disableKinds = ['rss']
{
"disableKinds": [
"rss"
]
}
默认情况下,每个源中的项目数量没有限制。根据需要在你的站点配置中更改此设置
hugo。
services:
rss:
limit: 42
[services]
[services.rss]
limit = 42
{
"services": {
"rss": {
"limit": 42
}
}
}
将 limit
设置为 -1
以生成每个源中无限数量的项目。
如果存在,内置的 RSS 模板将从你的站点配置中呈现以下值
hugo。
copyright: © 2023 ABC Widgets, Inc.
params:
author:
email: [email protected]
name: John Doe
copyright = '© 2023 ABC Widgets, Inc.'
[params]
[params.author]
email = '[email protected]'
name = 'John Doe'
{
"copyright": "© 2023 ABC Widgets, Inc.",
"params": {
"author": {
"email": "[email protected]",
"name": "John Doe"
}
}
}
包含源引用
要在呈现的页面的 head
元素中包含源引用,请将其放置在你的模板的 head
元素中
{{ with .OutputFormats.Get "rss" -}}
{{ printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink site.Title | safeHTML }}
{{ end }}
Hugo 将呈现为
<link rel="alternate" type="application/rss+xml" href="https://example.org/index.xml" title="ABC Widgets">
自定义模板
通过创建你自己的模板来覆盖 Hugo 的 嵌入式 RSS 模板,并遵循 模板查找顺序 中所示的命名约定。
例如,要为主页、章节、分类和术语页面使用不同的模板
layouts/
└── _default/
├── home.rss.xml
├── section.rss.xml
├── taxonomy.rss.xml
└── term.rss.xml
RSS 模板在上下文中接收 .Page
和 .Site
对象。