diff options
author | de-souza <43355143+de-souza@users.noreply.github.com> | 2020-03-17 15:16:06 +0300 |
---|---|---|
committer | de-souza <43355143+de-souza@users.noreply.github.com> | 2020-03-17 15:16:06 +0300 |
commit | 2df36682bd9aff37d3cdde6661febd4547e28038 (patch) | |
tree | 34ce903a19e97ac2451b652b7215053e5d874518 | |
parent | c676709c840914e57d4b5e2b9ec7bf2aadde93ac (diff) |
Add support for rssLimit and empty dates
-rw-r--r-- | layouts/_default/rss.xml | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index 037cfbc..abd0bda 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -1,10 +1,14 @@ -{{ `<?xml version="1.0" encoding="utf-8" ?>` | safeHTML }} -{{ with resources.Get "xml/base.tpl.xml" | resources.ExecuteAsTemplate "xml/base.xml" . | minify -}} -{{ printf `<?xml-stylesheet type="text/xsl" href=%q ?>` .Permalink | safeHTML }} -{{ end -}} +{{- $base_xml := resources.Get "xml/base.tpl.xml" | resources.ExecuteAsTemplate "xml/base.xml" . | minify }} +{{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }} +{{- $limit := .Site.Config.Services.RSS.Limit }} +{{- if ge $limit 1 }} + {{- $pages = $pages | first $limit }} +{{- end }} +{{- safeHTML `<?xml version="1.0" encoding="utf-8" ?>` }} +{{ printf `<?xml-stylesheet type="text/xsl" href=%q ?>` $base_xml.Permalink | 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> + {{ partial "title.html" . }} <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 }} @@ -13,14 +17,14 @@ <webMaster>{{ . }}{{ with site.Author.name }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with site.Copyright }} <copyright>{{ . }}</copyright>{{ end }}{{ with .Date | default nil }} <lastBuildDate>{{ .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 where site.RegularPages "Type" "in" site.Params.mainSections }} + {{ printf `<atom:link href=%q rel="self" type=%q />` .Permalink .MediaType | safeHTML }}{{ end }}{{ range $pages }} <item> <title>{{ .Title }}</title> - <link>{{ .Permalink }}</link> - <pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>{{ with site.Author.email }} + <link>{{ .Permalink }}</link>{{ with .PublishDate | default nil }} + <pubDate>{{ .Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>{{ end }}{{ with site.Author.email }} <author>{{ . }}{{ with site.Author.name }} ({{ . }}){{ end }}</author>{{ end }} <guid>{{ .Permalink }}</guid> - <description>{{ .Content | html }}</description> + <description>{{ html .Content }}</description> </item>{{ end }} </channel> </rss> |