summaryrefslogtreecommitdiffstats
path: root/layouts/_default/list.atom.xml
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-05-22 20:01:48 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-05-22 20:01:48 +0200
commit36150b5f88b2e513c6791b62aaf5eb3401d1c8a2 (patch)
tree3371e3a1e40458297c3e190b537f3d476752212f /layouts/_default/list.atom.xml
parentaa0c41042a3a8bfa6834d0bedbd0b5bb7eece762 (diff)
downloadgohugo-theme-ed-36150b5f88b2e513c6791b62aaf5eb3401d1c8a2.tar.gz
Rework feeds to provide support for section
Diffstat (limited to 'layouts/_default/list.atom.xml')
-rw-r--r--layouts/_default/list.atom.xml70
1 files changed, 70 insertions, 0 deletions
diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml
new file mode 100644
index 0000000..f82bb8b
--- /dev/null
+++ b/layouts/_default/list.atom.xml
@@ -0,0 +1,70 @@
+{{- $pctx := . -}}
+{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
+
+{{- $pages := slice -}}
+{{- if $.IsHome -}}
+ {{- $pages = where $pctx.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections -}}
+{{- else if $.IsSection -}}
+ {{- $pages = $pctx.RegularPages.ByDate.Reverse -}}
+{{- else -}}
+ {{- $pages = $pctx.Pages -}}
+{{- end -}}
+
+{{- $limit := site.Params.feedSize | default 25 -}}
+{{- $pages = $pages | first $limit -}}
+
+{{- safeHTML "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" }}
+<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="{{ site.LanguageCode }}">
+ {{ printf `<title type="html"><![CDATA[%s]]></title>` site.Title | safeHTML }}
+ {{ with site.Params.description }}{{ printf `<subtitle type="html"><![CDATA[%s]]></subtitle>` . | safeHTML }}{{ end }}
+ {{- $output_formats := .OutputFormats }}
+ {{- range $output_formats -}}
+ {{- $rel := (or (and (eq "atom" (.Name | lower)) "self") "alternate") -}}
+ {{- with $output_formats.Get .Name }}
+ {{ printf `<link href=%q rel=%q type=%q title=%q />` .Permalink $rel .MediaType.Type .Name | safeHTML }}
+ {{- end -}}
+ {{- end }}
+ {{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}{{ $logo = $logo.Resize "96x96" }}<icon>{{ $logo.Permalink | absURL }}</icon>
+ <logo>{{ $logo.Permalink | absURL }}</logo>
+ {{ with site.Author.name }}<author>
+ {{ printf `<name type="html"><![CDATA[%s]]></name>` . | safeHTML }}
+ {{ with site.Author.email }}<email>{{ . | html }}</email>{{ end }}
+ </author>{{ end }}
+ {{ with site.Params.Copyright }}
+ {{- $copyright := replace . "{year}" now.Year -}}
+ {{- $copyright = replace $copyright "&copy;" "©" }}<rights>{{ $copyright | plainify }}</rights>{{ end }}
+ <generator uri="https://gohugo.io" version="{{ hugo.Version }}">Hugo</generator>
+ {{ if not site.LastChange.IsZero }}<updated>{{ site.LastChange.UTC.Format site.Params.dateFormatFeed }}</updated>{{ end }}
+ {{ $uuid := sha1 (site.BaseURL | absURL) }}<id>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 }}</id>
+ {{- range $pages }}
+ <entry>
+ {{- $url := .Permalink | absURL }}{{ $uuid := sha1 (.Permalink | absURL) }}{{ $page := . }}
+ <category term="{{ .Section }}" />
+ {{ range (.GetTerms "tags") }}<category term="{{ .LinkTitle }}" />{{ end }}
+ <link rel="alternate" type="type/html" href="{{ $url }}?utm_source=atom_feed" />
+ {{ printf `<title type="html"><![CDATA[%s]]></title>` .Title | safeHTML }}
+ {{/* rel=related: See https://validator.w3.org/feed/docs/atom.html#link */}}
+ {{- range first 5 (site.RegularPages.Related .) }}
+ <link href="{{ .Permalink }}?utm_source=atom_feed" rel="related" type="text/html" title="{{ .Title }}" />
+ {{- end }}
+ <published>{{ (.PublishDate.Format site.Params.dateFormatFeed) | html }}</published>
+ {{ if ne .Date .Lastmod }}<updated>{{ .Lastmod.UTC.Format site.Params.dateFormatFeed }}</updated>{{ end }}
+ <id>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 }}</id>
+ {{ if .Params.author }}
+ {{- $author_type := (printf "%T" .Params.author) }}
+ {{- if eq $author_type "string" }}
+ <author>
+ <name>{{ .Params.author }}</name>
+ </author>
+ {{- else if eq $author_type "[]string" }}
+ {{ range .Params.author }}
+ <author>
+ <name>{{ .Name }}</name>
+ </author>
+ {{ end }}
+ {{- end }}
+ {{ end }}
+ {{ printf `<summary type="html"><![CDATA[%s]]></summary>` .Summary | safeHTML }}
+ </entry>
+ {{- end }}
+</feed>