refactor rss template

This commit is contained in:
Wonderfall 2023-12-31 20:09:48 +01:00
parent 4b45709402
commit 73484a80d7

View File

@ -42,42 +42,39 @@
{{- if ge $limit 1 }} {{- if ge $limit 1 }}
{{- $pages = $pages | first $limit }} {{- $pages = $pages | first $limit }}
{{- end }} {{- end }}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }} {{- 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/"> <feed xmlns="http://www.w3.org/2005/Atom">
<channel> <title>{{ if eq .Title site.Title }}{{ site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ site.Title }}{{ end }}</title>
<title>{{ if eq .Title site.Title }}{{ site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ site.Title }}{{ end }}</title> <link rel="alternate" href="{{ (.OutputFormats.Get "HTML").Permalink }}" />
<link>{{ .Permalink }}</link> <link rel="self" href="{{ (.OutputFormats.Get "RSS").Permalink }}" />
<description>Recent content {{ if ne .Title site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ site.Title }}</description> <subtitle>Recent content {{ if ne .Title site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ site.Title }}</subtitle>
{{- with site.Params.images }} <id>{{ .Permalink }}</id>
<image> <generator uri="http://gohugo.io" version="{{ hugo.Version }}">Hugo</generator>
<title>{{ site.Title }}</title> <language>{{ site.Language.LanguageCode }}</language>
<url>{{ index . 0 | absURL }}</url> <updated>{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}</updated>
<link>{{ index . 0 | absURL }}</link> <author>
</image> {{ with $authorName }}<name>{{ . }}</name>{{ end }}
{{- end }} {{ with $authorEmail }}<name>{{ . }}</name>{{ end }}
<generator>Hugo -- gohugo.io</generator> </author>
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }} {{ with site.Copyright }}<rights>{{ . }}</rights>{{ end }}
<managingEditor>{{.}}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with site.Copyright }} {{- range $pages }}
<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`) }} {{- if and (ne .Layout `search`) (ne .Layout `archives`) }}
<item> <entry>
<title>{{ .Title }}</title> <title>{{ .Title }}</title>
<link>{{ .Permalink }}</link> <link rel="alternate" href="{{ .Permalink }}" />
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate> <id>{{ .Permalink }}</id>
{{- with $authorEmail }}<author>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</author>{{ end }} <published>{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}</published>
<guid>{{ .Permalink }}</guid> <updated>{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}</updated>
<description>{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end -}}</description> <summary type="html">{{ with .Description | html }}{{ . }}{{ else }}{{ .Summary | html }}{{ end -}}</summary>
{{- if site.Params.ShowFullTextinRSS }} {{- if site.Params.ShowFullTextinRSS }}
<content:encoded>{{ (printf "<![CDATA[%s]]>" .Content) | safeHTML }}</content:encoded> <content type="html">{{ .Content | html }}</content>
{{- end }} {{- end }}
</item> </entry>
{{- end }} {{- end }}
{{- end }} {{- end }}
</channel>
</rss> </feed>