diff options
author | dataCobra <datacobra@mailbox.org> | 2020-04-21 13:07:59 +0300 |
---|---|---|
committer | dataCobra <datacobra@mailbox.org> | 2020-04-21 13:07:59 +0300 |
commit | afa2758cf5d396b6ee1bf6818246bad158dab585 (patch) | |
tree | 7be90374d8e7761f47275b309055cd4cb2f3cc31 | |
parent | f081bb851659af856c7181fb4cc69403ad60ff5b (diff) |
Fix #5 with an updated rss.xml2.0-1
-rw-r--r-- | exampleSite/config.toml | 6 | ||||
-rw-r--r-- | features.txt | 2 | ||||
-rw-r--r-- | layouts/_default/rss.xml | 71 |
3 files changed, 46 insertions, 33 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 6b34997..66aab17 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -48,10 +48,10 @@ disqusShortname = "" #favicon = true # Add list of sections that should show up on the homepage - mainSections = ["post"] + mainSections = ["post"] - # Add list of Sections that should be considered by RSS - feedSections = ["post"] + # Add list of Sections/Types that should no be considered by RSS + #nofeedSections = ["post"] # Deactivate Taxonomies for specific page types #disableTaxoTypes = [""] diff --git a/features.txt b/features.txt index 0a70929..a62643d 100644 --- a/features.txt +++ b/features.txt @@ -10,7 +10,7 @@ .Site.Params.disableDisqusTypes # Deactivate Disqus for specific page types .Site.Params.excludedTypes # Exclude specific types in lists .Site.Params.mainSections # Add list of sections that should show up on the homepage -.Site.Params.feedSections # Add list of sections that should be considered by RSS +.Site.Params.nofeedSections # Add list of sections/types that should not be considered by RSS .Site.Params.disableTaxoTypes # Deactivate taxonomies for specific page types .Site.Params.favicon # Activate favicons for the website diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index f713026..ba12a4f 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -1,44 +1,57 @@ -{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }} +{{- $pctx := . -}} +{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}} +{{- $pages := slice -}} +{{- if or $.IsHome $.IsSection -}} +{{- if .Site.Params.nofeedSections -}} +{{- $pages = where $pctx.RegularPages "Type" "not in" .Site.Params.nofeedSections -}} +{{- else -}} +{{- $pages = $pctx.RegularPages -}} +{{- end -}} +{{- else -}} +{{- if .Site.Params.nofeedSections -}} +{{- $pages = where $pctx.Pages "Type" "not in" .Site.Params.nofeedSections -}} +{{- else -}} +{{- $pages = $pctx.Pages -}} +{{- end -}} +{{- end -}} +{{- $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"> <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 {{ $baseurl := urls.Parse .Site.BaseURL }}{{ $baseurl.Host }}</description> - <generator>Hugo {{ hugo.Version }}</generator>{{ with .Site.LanguageCode }} + <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>{{ . | markdownify | plainify }}</copyright>{{end}}{{ if not .Date.IsZero }} - <lastBuildDate>{{ now.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }} + <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 }} - {{ $pages := .Site.RegularPages }} - {{ if .Site.Params.feedSections }} - {{ $pages = where .Site.RegularPages "Section" "in" .Site.Params.feedSections }} - {{ else }} - {{ $pages = where .Site.RegularPages "Section" "in" .Site.Params.mainSections }} + {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }} {{ end }} {{ range $pages }} - {{- if ne .Params.nofeed true -}} - <item> - <title>{{ .Title }}</title> - <link>{{ .Permalink }}</link> - <pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</pubDate> - {{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}} - <guid>{{ .Permalink }}</guid> - <description> - {{ if isset .Params "description" }} - {{ .Description }} - {{ else if gt (len .Plain) 120 }} - {{ slicestr .Plain 0 120 }}... - {{ else }} - {{ .Plain }} - {{ end }} - </description> - </item> - {{ end -}} + {{- if ne .Params.nofeed 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> + <description> + {{ if isset .Params "description" }} + {{ .Description }} + {{ else if gt (len .Plain) 120 }} + {{ slicestr .Plain 0 120 | htmlUnescape }}... + {{ else }} + {{ .Plain | htmlUnescape }} + {{ end }} + </description> + </item> + {{ end -}} {{ end }} </channel> </rss> - |