summaryrefslogtreecommitdiffstats
path: root/layouts/_default
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
parentaa0c41042a3a8bfa6834d0bedbd0b5bb7eece762 (diff)
downloadgohugo-theme-ed-36150b5f88b2e513c6791b62aaf5eb3401d1c8a2.tar.gz
Rework feeds to provide support for section
Diffstat (limited to 'layouts/_default')
-rw-r--r--layouts/_default/list.atom.xml (renamed from layouts/_default/home.atom.xml)43
-rw-r--r--layouts/_default/list.feed.xml (renamed from layouts/_default/home.feed.xml)38
-rw-r--r--layouts/_default/list.json.json (renamed from layouts/_default/home.json.json)29
3 files changed, 84 insertions, 26 deletions
diff --git a/layouts/_default/home.atom.xml b/layouts/_default/list.atom.xml
index 575b2df..f82bb8b 100644
--- a/layouts/_default/home.atom.xml
+++ b/layouts/_default/list.atom.xml
@@ -1,29 +1,52 @@
-{{ safeHTML "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" }}
+{{- $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 }}
- <link href="{{ site.BaseURL | absURL }}" type="text/html" />
- {{ with site.Home.OutputFormats.Get "ATOM" }}<link href="{{ .Permalink | absURL }}" rel="self" type="{{ .MediaType.Type | html }}" />{{ end }}
- {{ with site.Home.OutputFormats.Get "FEED"}}<link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
- {{ with site.Home.OutputFormats.Get "JSON"}}<link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
- {{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }}<icon>{{ $logo.Permalink | absURL }}</icon>
+ {{- $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 }}{{ printf `<rights type="html"><![CDATA[%s]]></rights>` . | safeHTML }}{{ 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>
- {{ $feedsize := site.Params.feedSize | default 25 }}
- {{- range first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }}
+ {{- 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 }}" />
+ <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>
diff --git a/layouts/_default/home.feed.xml b/layouts/_default/list.feed.xml
index 714bc07..5a276ec 100644
--- a/layouts/_default/home.feed.xml
+++ b/layouts/_default/list.feed.xml
@@ -1,4 +1,19 @@
-{{ safeHTML "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" }}
+{{- $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\" ?>" }}
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
@@ -12,7 +27,7 @@
{{ printf `<title type="html"><![CDATA[%s RSS 2.0]]></title>` site.Title | safeHTML }}
</channel>
<link type="text/html">{{ site.BaseURL | absURL }}</link>
- {{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }}
+ {{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}{{ $logo = $logo.Resize "96x96" }}
<image>
<url>{{ $logo.Permalink | absURL }}</url>
{{ printf `<title type="html"><![CDATA[%s RSS 2.0]]></title>` site.Title | safeHTML }}
@@ -20,21 +35,26 @@
<width>{{ $logo.Width }}</width>
<height>{{ $logo.Height }}</height>
</image>
- <link href="{{ site.BaseURL | absURL }}" type="text/html" />
- {{ with site.Home.OutputFormats.Get "FEED"}}<atom:link href="{{ .Permalink | absURL }}" rel="self" type="{{ .MediaType.Type | html }}" />{{end}}
- {{ with site.Home.OutputFormats.Get "ATOM"}}<atom:link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
- {{ with site.Home.OutputFormats.Get "JSON"}}<link href="{{ .Permalink | absURL }}" rel="alternate" type="{{ .MediaType.Type | html }}" />{{end}}
+ {{- $output_formats := .OutputFormats }}
+ {{- range $output_formats -}}
+ {{- $rel := (or (and (eq "feed" (.Name | lower)) "self") "alternate") -}}
+ {{- with $output_formats.Get .Name }}
+ {{ printf `<atom:link href=%q rel=%q type=%q title=%q />` .Permalink $rel .MediaType.Type .Name | safeHTML }}
+ {{- end -}}
+ {{- end }}
{{ with site.Params.description }}{{ printf `<description type="html"><![CDATA[%s]]></description>` . | safeHTML }}{{ end }}
<generator>Hugo {{ hugo.Version }}</generator>
{{ with site.Author.name }}{{ printf `<dc:creator type="html"><![CDATA[%s]]></dc:creator>` . | safeHTML }}{{ end }}
{{ with site.LanguageCode }}<language>{{ . }}</language>{{ end }}
- {{ with site.Params.Copyright }}{{ printf `<copyright type="html"><![CDATA[%s]]></copyright>` . | safeHTML }}{{ end }}
+ {{ with site.Params.Copyright }}
+ {{- $copyright := replace . "{year}" now.Year -}}
+ {{- $copyright = replace $copyright "&copy;" "©" }}<copyright>{{ $copyright | plainify }}</copyright>{{ end }}
{{ if not site.LastChange.IsZero }}<lastBuildDate>{{ site.LastChange.UTC.Format site.Params.dateFormatRFC822Z | html }}</lastBuildDate>{{ end }}
{{ $feedsize := site.Params.feedSize | default 25 }}
- {{- range first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }}
+ {{- range $pages }}
<item>
{{ printf `<title type="html"><![CDATA[%s]]></title>` .Title | safeHTML }}
- <link>{{ .Permalink | absURL }}</link>
+ <link>{{ .Permalink | absURL }}?utm_source=rss_feed</link>
<pubDate>{{ .PublishDate.UTC.Format site.Params.dateFormatRFC822Z | html }}</pubDate>
<category>{{ .Section }}</category>
{{ range (.GetTerms "tags") }}<category>{{ .LinkTitle }}</category>{{end}}
diff --git a/layouts/_default/home.json.json b/layouts/_default/list.json.json
index 6df1514..6151211 100644
--- a/layouts/_default/home.json.json
+++ b/layouts/_default/list.json.json
@@ -1,10 +1,25 @@
+{{- $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 -}}
+
{
"version": "https://jsonfeed.org/version/1.1",
"title": {{ (printf "%s JSON Feed" site.Title) | htmlUnescape | jsonify }},
- "home_page_url": {{ site.BaseURL | absURL | jsonify }},
- {{ with .OutputFormats.Get "JSON" }}"feed_url": {{.Permalink | absURL | jsonify }},{{ end }}
- {{ with site.Params.description}}"description": {{site.Params.description | jsonify}},{{end}}
- {{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png" ) }}{{ $logo = $logo.Resize "96x96" }}
+ "home_page_url": {{ printf "%s?utm_source=json_feed" site.BaseURL | absURL | jsonify }},
+ {{ with .OutputFormats.Get "JSON" }}"feed_url": {{ .Permalink | absURL | jsonify }},{{ end }}
+ {{ with site.Params.description}}"description": {{ site.Params.description | jsonify }},{{ end }}
+ {{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}{{ $logo = $logo.Resize "96x96" }}
"icon": {{ $logo.Permalink | jsonify }},
"favicon": {{ $logo.Permalink | jsonify }},
{{ with site.Author.name }}"authors": [
@@ -14,11 +29,11 @@
}
],{{ end }}
{{ with site.LanguageCode }}"language" : "{{ . }}",{{ end }}{{ $feedsize := site.Params.feedSize | default 25 }}
- "items": [{{ $r := first $feedsize (where site.RegularPages.ByDate.Reverse "Type" "in" site.Params.mainSections) }} {{ range $i, $ := $r }}{{ if $i }},{{ end }}
+ "items": [{{ range $i, $ := $pages }}{{ if $i }},{{ end }}
{
"id": {{ $uuid := sha1 (.Permalink | absURL)}}"{{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}}",
- "url": {{ .Permalink | jsonify }},
- "title": {{ .Title | plainify | chomp | jsonify }},
+ "url": {{ printf "%s?utm_source=json_feed" .Permalink | jsonify }},
+ "title": {{ .Title | plainify | chomp | jsonify }},
"summary": {{ .Summary | plainify | chomp | jsonify }},
"date_published": {{ .PublishDate.UTC.Format site.Params.dateFormatFeed | jsonify }}{{ if ne .Date .Lastmod }},
"date_modified" : {{ .Lastmod.UTC.Format site.Params.dateFormatFeed | jsonify }}{{ end }}