Skip to content

Commit

Permalink
feat(RSS): add support for full post content in RSS feed, closes #109
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-sid committed Sep 16, 2023
1 parent b791e6a commit b7a4e4c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ disqusShortname = ''
# When building for production it will be minified.
# The file `custom.js` is loaded on each page (before body tag ends).
dateFormat = "January 2, 2006" # default date format used on various pages
# See https://gohugo.io/functions/format/#hugo-date-and-time-templating-reference for available date formats
# See https://gohugo.io/functions/format/#hugo-date-and-time-templating-reference for available date formats.
rssFeedDescription = "summary" # available options: 1) summary 2) full
# summary - includes a short summary of the blog post in the RSS feed. Generated using Hugo .Summary .
# full - includes full blog post in the RSS feed. Generated using Hugo .Content .
# By default (or if nothing is specified), summary is used.

[params.author]
avatar = "avatar.jpg" # put the file in assets folder; also ensure that image has same height and width
Expand Down
46 changes: 46 additions & 0 deletions layouts/_default/rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- Taken from Hugo default RSS template: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml -->
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = $pctx.RegularPages -}}
{{- else -}}
{{- $pages = $pctx.Pages -}}
{{- end -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- $rssFeedDescription := .Site.Params.rssFeedDescription | default "summary" -}}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
<generator>Hugo -- gohugo.io</generator>
<language>{{ site.Language.LanguageCode }}</language>{{ with .Site.Author.email }}
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "RSS" -}}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{- end -}}
{{ range $pages }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
<guid>{{ .Permalink }}</guid>
{{ if eq $rssFeedDescription "summary"}}
<description>{{ .Summary | html }}</description>
{{ else if (eq $rssFeedDescription "full")}}
<description>{{ .Content | html }}</description>
{{ else }} {{ errorf "Error in RSS feed generation %q" .Path }}
{{ end }}
</item>
{{ end }}
</channel>
</rss>

0 comments on commit b7a4e4c

Please sign in to comment.