When building a website with Hugo, subscribing to RSS only fetches part of the content (e.g. the summary or the first half, which is blank at the end), usually because Hugo’s default RSS template only outputs a summary of the article (’. Summary’) instead of the full text (’. Content`)。 This is a built-in behavior of Hugo that aims to keep RSS files concise, and can be solved by customizing RSS templates.
Cause analysis
- Default Template Limitations
Hugo’s default RSS template (built into Hugo’s core code)
uses the ‘{{ . Summary | html }}’, which will only output an auto-generated summary of the article (usually part of the beginning of the article and limited length). If you don’t explicitly specify the full-text output, the following content will naturally be empty. - Manual Summary Settings The '
’ delimiter is used in the article’s Markdown file, and Hugo uses this delimiter as a delimiter to generate a summary, and RSS defaults to only showing content before the separator. 3. Topic Coverage Issues The Hugo theme has a custom RSS template (located in ’themes/yourthemes/layouts/_default/rss.xml’), and it is possible that the theme developer chooses to output only the summary instead of the full text.
Workaround
To make the RSS contain the full text, you need to customize the RSS template, adding the ‘. Summary’ with ‘. Content`。 The specific steps are as follows:
Create or edit RSS templates
- By default, Hugo uses built-in RSS templates. If you don’t have a ’layouts/_default/rss.xml’ file in your project’s root or theme directory, you’ll need to create one.
- Steps:
- Create the folder ’layouts/_default/’ in the root directory of the project (if it doesn’t exist).
- Create the file ‘rss.xml’ with the path ’layouts/_default/rss.xml’.
- Copy the code from the official Hugo default template (available from Hugo GitHub) or simply use the simplified version below:
1<?xml version="1.0" encoding="utf-8" standalone="yes"?>
2<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
3 <channel>
4 <title>{{ .Site.Title }}</title>
5 <link>{{ .Site.BaseURL }}</link>
6 <description>{{ .Site.Title }} 的最新内容</description>
7 <generator>Hugo -- gohugo.io</generator>
8 {{ with .Site.LanguageCode }}<language>{{ . }}</language>{{ end }}
9 {{ with .OutputFormats.Get "RSS" }}
10 <atom:link href="{{ .Permalink }}" rel="self" type="application/rss+xml" />
11 {{ end }}
12 {{ range .Site.RegularPages }}
13 <item>
14 <title>{{ .Title }}</title>
15 <link>{{ .Permalink }}</link>
16 <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</pubDate>
17 <guid>{{ .Permalink }}</guid>
18 <description>{{ .Content | html }}</description>
19 </item>
20 {{ end }}
21 </channel>
22</rss>
Modify key sections
- In the above template, ‘
{{ . Content | html }} ’ is the key line. Here the ‘. Content’, which outputs the full HTML content of the article instead of ‘. Summary`。 - If you’re using the default template, it might be ‘
{{ . Summary | html }} ’, which is why only part of the content is displayed.
Regenerate the website
- After modifying the template, run the ‘hugo’ command to regenerate the static file.
- Check the generated ‘public/index.xml’ (or other RSS file path you configured) to confirm that
the full text is included in the ’’’ tag.
Test RSS feeds
- Subscribe to your RSS address (‘domain/rss.xml’ for bloggers) with an RSS reader (e.g. feeder) to confirm that the full text is displayed correctly.
Precautions
- Image Path Problem
If there are images in the article, RSS may not correctly display images relative to the path (e.g. ‘
’). You’ll need to make sure that the image uses an absolute path, which can be done in the template with ‘. Permalink’s Dynamic Splicing:
1<description>{{ . Content | replaceRE `<img src="/(.*?)">` (printf `<img src="%s$1">` . Site.BaseURL) | html }}</description>
- File size Full-text output can cause RSS files to become larger, especially if there are many articles. If your site has a lot of long articles, it is recommended to limit the number of RSS entries in ‘hugo.yaml’:
1[services]
2[services.rss]
3limit = 10 # The limit is the last 10 articles
- Manual summarization is compatible with full text If you still want to keep the manual summary (’’) but want the RSS to show the full text, you can either leave the article without using a separator, or explicitly use ‘. Content’ and ignore the summary.