Skip to content

Commit

Permalink
add main content in rss
Browse files Browse the repository at this point in the history
  • Loading branch information
reorx committed Apr 7, 2023
1 parent 570b3bc commit dcef762
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions site/layouts/_default/rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- $pages := .Pages -}}
{{- if $.IsHome -}}
{{/* get all regular pages instead of pages in a section */}}
{{- $pages = where site.RegularPages "Section" "in" site.Params.mainSections -}}
{{- end }}
{{- $pages = where $pages "Params.hidden" "!=" true -}}

{{- $limit := site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}

{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | 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>{{ site.Title }}</title>
<link>{{ .Permalink }}</link>
<description>Recent updates on {{ site.Title }}</description>
{{- with site.Params.logo }}
<image>
<url>{{ .icon | absURL }}</url>
<link>{{ .icon | absURL }}</link>
</image>
{{- end }}
<generator>Hugo -- gohugo.io</generator>{{ with site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ 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 }}
{{- if and (ne .Layout `search`) (ne .Layout `archives`) }}
<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>
<description>{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end -}}</description>
{{- if not site.Params.RSSNoContent}}
<content:encoded>{{ (printf "<![CDATA[%s]]>" .Content) | safeHTML }}</content:encoded>
{{- end }}
</item>
{{- end }}
{{ end }}
</channel>
</rss>

0 comments on commit dcef762

Please sign in to comment.