Extending RSS in Hugo
Publish date: Apr 1, 2023
Last updated: Apr 3, 2023
Last updated: Apr 3, 2023
Get a copy of the default RSS template that ships with Hugo and put it in root/layouts
dir.
- layouts
- partials
- rss-tag.html
- rss-reply.html
- rss.xml
- partials
Full Content
Make your subscribers happy by updating {{ .Summary | html }}
to {{ .Content | html }}
.
Add Tags
I prefer adding this over the category element because there maybe some older or less feature-rich RSS readers that do not fully support the latter.
1. Create an rss-tag.html partial
<p>Tags:
{{ range $i, $e := .Params.tags -}}
{{- if $i -}}, {{ end -}}
<a href='{{ "/tags/" | relLangURL }}{{ . | urlize }}'>#{{ . }}</a>
{{- end -}}
</p>
2. Add partial to rss.xml
<description>
{{ .Content | html }}
{{ partial "rss-tag.html" . | html }}
</description>
Add Reply to Email
This redirects your subscribers to their email service with a dynamic subject: Reply to “Post Title”.
1. Create an rss-reply.html partial
<p style="font-size:1.3rem">
<a href='mailto:hi@example.com?subject=Reply%20to%20"{{ .Title }}"'>Reply to this post via email</a>
</p>
2. Add partial to rss.xml.
<description>
{{ .Content | html }}
{{ partial "rss-reply.html" . | html }}
</description>