Skip to main content

Getting Hugo to Provide a Full Feed in RSS

·2 mins
Blog Admin Hugo RSS
Omar Amin
Author
Omar Amin
Loves boxing, FOSS and Selfhosting

I wanted a full text RSS feed, posts to be tagged and readable formatting!

Heres the code I put into my layouts/index.rss.xml file:

{{- printf "<?xml-stylesheet href=\"/rss.xsl\" type=\"text/xsl\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <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>
    {{ with .Site.LanguageCode }}<language>{{.}}</language>{{end}}
    <managingEditor>{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>
    <webMaster>{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>
    {{ 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 .Paginator.Pages }}
    {{ if and (.IsPage) (.Params.date) }}
        <item>
        <title>{{ .Title }}</title>
        <link>{{ .Permalink }}</link>
        <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
        <author>{{ with $.Site.Author.name }} ({{.}}){{end}}</author>
        <guid>{{ .Permalink }}</guid>
        <description>{{- .Description | html -}}</description>
        <content:encoded>
          {{ `<![CDATA[` | safeHTML }}
          {{ .Content }}
          {{ `]]>` | safeHTML }}
        </content:encoded>
        {{ range .Params.tags }}
          <category>{{ . }}</category>
        {{ end }}
        </item>
    {{ end }}
    {{ end }}
  </channel>
</rss>