Skip to content

Commit

Permalink
feat: optimize rss output format and add rss ignored support (#8)
Browse files Browse the repository at this point in the history
* feat: optimize rss output format and add rss ignored support

I optimized the rss format accoring to hugo best practice and add "rss_ignore" prarm to manually
ignore some pages to to fetched by rss readers

* fix: change some settings to keep original features and make it backward-compatible

* revert: reverted to orginal version to keep the icon

* fix: keep both webfeeds and content in rss settings
  • Loading branch information
pseudoyu authored Jul 4, 2022
1 parent 34aadcf commit f420b49
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions layouts/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{{- $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:webfeeds="http://webfeeds.org/rss/1.0">
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:webfeeds="http://webfeeds.org/rss/1.0" 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>
Expand All @@ -28,19 +28,18 @@
{{ with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{ end }}
{{ range $pages }}
{{ range $pages }}{{ if ne .Params.rss_ignore true }}
<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 .Site.Params.rssFullContent }}
<description>{{ .Content | html }}</description>
{{ else }}
<description>{{ .Summary | html }}</description>
{{ end }}
<description>{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end -}}</description>
{{- if .Site.Params.rssFullContent}}
<content:encoded>{{ (printf "<![CDATA[%s]]>" .Content) | safeHTML }}</content:encoded>
{{- end }}
</item>
{{ end }}
{{ end }}{{ end }}
</channel>
</rss>
</rss>

0 comments on commit f420b49

Please sign in to comment.