From 1867dc34c3f94b64580ab0b088012954807bfced Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Tue, 17 May 2022 15:46:41 +0200 Subject: Add RSS 2.0 support --- exampleSite/config.toml | 34 +++++++++++++++++++++----------- layouts/_default/home.atom.xml | 22 ++++++++++----------- layouts/_default/home.feed.xml | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 23 deletions(-) create mode 100644 layouts/_default/home.feed.xml diff --git a/exampleSite/config.toml b/exampleSite/config.toml index e0f0160..3e57fe9 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -18,17 +18,7 @@ disableKinds = ['RSS'] # TODO: # home = [ "HTML", "Atom", "JSON", "humanstxt" ] # section = [ "HTML", "Atom" ] - home = [ 'HTML', 'Atom', 'humanstxt' ] - -# For more see: https://gohugo.io/templates/output-formats/ -[outputFormats.humanstxt] - mediaType = 'text/plain' - baseName = 'humans' - rel = 'author' - isPlainText = true - isHTML = false - noUgly = true - permalinkable = false + home = [ 'HTML', 'Atom', 'FEED', 'humanstxt' ] # Atom feed. # For more see: https://validator.w3.org/feed/docs/atom.html#whatIsAtom @@ -50,6 +40,27 @@ disableKinds = ['RSS'] noUgly = true permalinkable = false +# no collision with buildin RSS +[outputFormats.FEED] + name = 'Feed' + mediaType = 'text/xml' + baseName = 'feeds/feed.rss' + rel = 'alternate' + isPlainText = false + isHTML = false + noUgly = true + permalinkable = false + +# For more see: https://gohugo.io/templates/output-formats/ +[outputFormats.humanstxt] + mediaType = 'text/plain' + baseName = 'humans' + rel = 'author' + isPlainText = true + isHTML = false + noUgly = true + permalinkable = false + [mediaTypes] [mediaTypes.'text/xml'] suffixes = ['xml'] @@ -84,6 +95,7 @@ disableKinds = ['RSS'] # Posts date format, for example: 2006-01-02 dateformat = 'January 02, 2006' dateFormatFeed = '2006-01-02T15:04:05Z07:00' + dateFormatRFC822Z = '02 Jan 2006 15:04:05 UT' # Show "Read more" button in list if true readmore = true # RSS/Atom feed size diff --git a/layouts/_default/home.atom.xml b/layouts/_default/home.atom.xml index 8e29bf3..5368ab7 100644 --- a/layouts/_default/home.atom.xml +++ b/layouts/_default/home.atom.xml @@ -1,29 +1,27 @@ -{{ `` | safeHTML }} +{{ safeHTML "" }} {{ printf `<![CDATA[%s]]>` site.Title | safeHTML }} - {{ with site.Params.description -}} - {{- printf `` . | safeHTML }} - {{- end }} - {{ with site.Home.OutputFormats.Get "Atom" }}{{ end }} + {{ with site.Params.description }}{{ printf `` . | safeHTML }}{{ end }} + + {{ with site.Home.OutputFormats.Get "ATOM" }}{{ end }} + {{ with site.Home.OutputFormats.Get "FEED"}}{{end}} {{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }}{{ $logo.Permalink | absURL }} {{ $logo.Permalink | absURL }} {{ with site.Author.name }} {{ printf `` . | safeHTML }} - {{ with site.Author.email }}{{ . | html }}{{end}} + {{ with site.Author.email }}{{ . | html }}{{ end }} {{ end }} - {{ with site.Params.Copyright -}} - {{- printf `` . | safeHTML -}} - {{- end }} + {{ with site.Params.Copyright }}{{ printf `` . | safeHTML }}{{ end }} Hugo {{ if not site.LastChange.IsZero }}{{ site.LastChange.UTC.Format site.Params.dateFormatFeed }}{{ end }} - {{ $uuid := sha1 (site.BaseURL | absURL)}}urn:uuid:{{ substr $uuid 0 8 }}-{{ substr $uuid 8 4 }}-5{{ substr $uuid 13 3 }}-{{ substr $uuid 16 1 }}9{{ substr $uuid 17 2 }}-{{ substr $uuid 21 12 }} + {{ $uuid := sha1 (site.BaseURL | absURL) }}urn:uuid:{{ substr $uuid 0 8 }}-{{ substr $uuid 8 4 }}-5{{ substr $uuid 13 3 }}-{{ substr $uuid 16 1 }}9{{ substr $uuid 17 2 }}-{{ substr $uuid 21 12 }} {{ $feedsize := site.Params.feedSize | default 25 }} {{- range first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }} - {{- $url := .Permalink | absURL }}{{ $uuid := sha1 (.Permalink | absURL)}}{{ $page := .}} - + {{- $url := .Permalink | absURL }}{{ $uuid := sha1 (.Permalink | absURL) }}{{ $page := . }} + {{ range (.GetTerms "tags") }}{{ end }} {{ printf `<![CDATA[%s]]>` .Title | safeHTML }} diff --git a/layouts/_default/home.feed.xml b/layouts/_default/home.feed.xml new file mode 100644 index 0000000..2f33114 --- /dev/null +++ b/layouts/_default/home.feed.xml @@ -0,0 +1,44 @@ +{{ safeHTML "" }} + + + {{ printf `<![CDATA[%s RSS]]>` site.Title | safeHTML }} + + {{ "/" | absURL }} + {{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }} + + {{ $logo.Permalink | absURL }} + {{ printf `<![CDATA[%s RSS]]>` site.Title | safeHTML }} + {{ "/" | absURL }} + {{ $logo.Width }} + {{ $logo.Height }} + + + {{ with site.Home.OutputFormats.Get "FEED"}}{{end}} + {{ with site.Home.OutputFormats.Get "ATOM"}}{{end}} + {{ with site.Params.description }}{{ printf `` . | safeHTML }}{{ end }} + Hugo + {{ with site.Author.name }}{{ printf `` . | safeHTML }}{{ end }} + {{ with site.LanguageCode }}{{ . }}{{ end }} + {{ with site.Params.Copyright }}{{ printf `` . | safeHTML }}{{ end }} + {{ if not site.LastChange.IsZero }}{{ site.LastChange.UTC.Format site.Params.dateFormatRFC822Z | html }}{{ end }} + {{ $feedsize := site.Params.feedSize | default 25 }} + {{- range first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }} + + {{ printf `<![CDATA[%s]]>` .Title | safeHTML }} + {{ .Permalink | absURL }}{{ $date := .PublishDate.UTC }} + {{ $date.Format site.Params.dateFormatRFC822Z | html }} + {{ .Section }} + {{ range (.GetTerms "tags") }}{{ .LinkTitle }}{{end}} + {{ md5 .Permalink }} + {{ printf `` .Summary | safeHTML }} + + {{ end }} + -- cgit v1.2.3