Fix several issues with the Atom feeds

- Make sure Author info populates correctly
- Sort posts by Date
- Remove un-dated posts from the feed
- Remove Draft posts from the feed if the site isn't in Development mode
This commit is contained in:
Eryn Wells 2024-11-04 15:46:15 -08:00
parent 4689129355
commit 32762afb55
5 changed files with 19 additions and 16 deletions

View file

@ -1,7 +1,6 @@
{{- $page := . -}} {{- $pages := .RegularPagesRecursive.ByDate.Reverse -}}
{{- $pages := $page.RegularPages -}} {{- $limit := int $.Site.Config.Services.RSS.Limit -}}
{{- $limit := $.Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}} {{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}} {{- $pages = $pages | first $limit -}}
{{- end -}} {{- end -}}
{{ partial "feeds/atom/base.xml" (dict "context" $page "pages" $pages "limit" $limit) }} {{ partial "feeds/atom/base.xml" (dict "context" . "pages" $pages "limit" $limit) }}

View file

@ -0,0 +1 @@
section.atom

View file

@ -1,7 +1,6 @@
{{- $pages := where .Site.RegularPages "Draft" "eq" false -}} {{- $pages := .Site.RegularPages.ByDate.Reverse -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}} {{- $limit := int $.Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}} {{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}} {{- $pages = $pages | first $limit -}}
{{- end -}} {{- end -}}
{{ partial "feeds/atom/base.xml" (dict "context" . "pages" $pages) }} {{ partial "feeds/atom/base.xml" (dict "context" . "pages" $pages) }}

1
layouts/index.xml Symbolic link
View file

@ -0,0 +1 @@
index.atom

View file

@ -4,23 +4,26 @@
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }} {{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<feed xmlns="http://www.w3.org/2005/Atom"> <feed xmlns="http://www.w3.org/2005/Atom">
<title>{{ $context.Site.Title }}</title> <title>{{ $context.Site.Title }}</title>
<link href="{{ $context.Permalink }}" /> {{ with $context.OutputFormats.Get "Atom" -}}
<link href="{{ `/feed.atom` | absURL }}" rel="self" /> <link rel="self" type="application/atom+xml" href="{{ .Permalink }}" />
{{- end }}
<link href="{{ `/icons/favicon.png` | absURL }}" rel="shortcut icon" /> <link href="{{ `/icons/favicon.png` | absURL }}" rel="shortcut icon" />
{{ with $context.Date }} {{ with $context.Date -}}
<updated>{{ . | time.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated> <updated>{{ . | time.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>
{{ end }} {{- end -}}
<id>{{ $context.Permalink }}</id> <id>{{ $context.Permalink }}</id>
{{ with $context.Site.Author }} {{ with $context.Site.Params.Author -}}
<author> <author>
{{ with .name }}<name>{{ . }}</name>{{ end }} {{ with .name }}<name>{{ . }}</name>{{ end }}
{{ with .email }}<email>{{ . }}</email>{{ end }} {{ with .email }}<email>{{ . }}</email>{{ end }}
<uri>{{ $context.Site.Home.Permalink }}</uri> <uri>{{ $context.Site.Home.Permalink }}</uri>
</author> </author>
{{ end }} {{- end }}
<generator version="{{ hugo.Version }}" uri="https://gohugo.io">Hugo {{ hugo.Version }}</generator> <generator version="{{ hugo.Version }}" uri="https://gohugo.io">Hugo {{ hugo.Version }}</generator>
<rights>© 2020-{{ now.Year }} Eryn Wells</rights> <rights>© 2020-{{ now.Year }} Eryn Wells</rights>
{{ range $pages }} {{ range $pages -}}
{{ .Render "atom_entry" }} {{- if and (not .Date.IsZero) (or hugo.IsDevelopment (not .Draft)) -}}
{{ end }} {{ .Render "atom_entry" }}
{{- end -}}
{{- end -}}
</feed> </feed>