From 7f144fbe174fe62dd97d634d8d1edd6f3131a3de Mon Sep 17 00:00:00 2001 From: Will Faught Date: Sat, 23 Sep 2023 15:41:58 -0700 Subject: [PATCH] Clean up, random fixes for Atom, RSS --- layouts/_default/list.atom.xml | 189 +++++++++++++++++---------------- layouts/_default/rss.xml | 28 +++-- 2 files changed, 109 insertions(+), 108 deletions(-) diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml index 663356df..a1e24ae6 100644 --- a/layouts/_default/list.atom.xml +++ b/layouts/_default/list.atom.xml @@ -1,36 +1,52 @@ {{ $page := . }} {{ $authors := $page.Param "paige.feed.atom.authors" }} -{{ $lang := site.LanguageCode | default site.Language.Lang }} +{{ $format := "2006-01-02T15:04:05Z07:00" }} +{{ $html := $page.AlternativeOutputFormats.Get "html" }} +{{ $id := "" }} +{{ $ids := dict }} +{{ $language := site.LanguageCode | default site.Language.Lang }} {{ $limit := site.Config.Services.RSS.Limit }} {{ $pagetitle := $page.Title | markdownify }} -{{ $rights := site.Copyright }} +{{ $rights := site.Copyright | markdownify }} {{ $sitetitle := site.Title | markdownify }} {{ $subpages := (cond $page.IsHome site $page).RegularPages }} -{{ $subtitle := $page.Description }} +{{ $subtitle := $page.Description | markdownify }} {{ $title := "" }} -{{ $updated := site.LastChange }} +{{ $updated := site.LastChange.Format $format }} + +{{ if $page.Params.id }} + {{ $id = $page.Params.id }} +{{ else if not $page.Date.IsZero }} + {{ $id = printf "tag:%s,%s:%s" (urls.Parse site.BaseURL).Host (.Date.Format "2006-01-02") (.Date.Format $format) }} +{{ else }} + {{ $id = $page.Permalink }} +{{ end }} + +{{ $subpages = where $subpages "Params.paige.feed.hide_page" "ne" true }} + +{{ if ge $limit 0 }} + {{ $subpages = $subpages | first $limit }} +{{ end }} {{ if and $pagetitle $sitetitle }} {{ if $page.IsHome }} - {{ $title = $pagetitle | safeHTML }} + {{ $title = $pagetitle }} {{ else }} - {{ $title = printf "%s · %s" $pagetitle $sitetitle | safeHTML }} + {{ $title = printf "%s · %s" $pagetitle $sitetitle }} {{ end }} {{ else if $pagetitle }} - {{ $title = $pagetitle | safeHTML }} + {{ $title = $pagetitle }} {{ else if $sitetitle }} - {{ $title = $sitetitle | safeHTML }} + {{ $title = $sitetitle }} {{ end }} -{{ $subpages = where $subpages "Params.paige.feed.hide_page" "ne" true }} - -{{ if ge $limit 0 }} - {{ $subpages = $subpages | first $limit }} +{{ if not $title }} + {{ warnf "layouts/_default/list.atom.xml: Page %s does not have a title" $page.RelPermalink }} {{ end }} {{ printf "" | safeHTML }} - + {{ range $authors }} {{ with .email }} @@ -47,87 +63,59 @@ {{ end }} - {{ $id := "" }} - - {{ if .Params.id }} - {{ $id = .Params.id }} - {{ else if not $page.Date.IsZero }} - {{ $id = printf "tag:%s,%s:%s" (urls.Parse site.BaseURL).Host (.Date.Format "2006-01-02") (.Date.Format "2006-01-02T15:04:05Z07:00") }} - {{ else }} - {{ $id = .Permalink }} - {{ end }} - {{ $id }} - {{ printf `` ($page.Permalink | safeURL) | safeHTML }} - {{ with $page.AlternativeOutputFormats.Get "html" }} - {{ printf `` (.Permalink | safeURL) .MediaType | safeHTML }} + {{ range $page.OutputFormats }} + {{ $rel := cond (eq .Permalink $page.Permalink) "self" .Rel }} + + {{ printf `` .Permalink $rel .MediaType | safeHTML }} {{ end }} {{ range $t := $page.Translations }} {{ range .OutputFormats }} - {{ if eq .Rel "alternate" }} - {{ printf `` (.Permalink | safeURL) $t.Lang .MediaType | safeHTML }} - {{ end }} + {{ printf `` .Permalink $t.Lang .Rel .MediaType | safeHTML }} {{ end }} {{ end }} {{ with $rights }} - {{ printf "" (. | markdownify) | safeHTML }} + {{ printf "" . | safeHTML }} {{ end }} {{ with $subtitle }} - {{ printf "" (. | markdownify) | safeHTML}} - {{ end }} - - {{ if not $title }} - {{ warnf "layouts/_default/list.atom.xml: Page %s does not have a title" $page.RelPermalink }} + {{ printf "" . | safeHTML}} {{ end }} - {{ printf `<![CDATA[%s]]>` ($title | markdownify) | safeHTML }} - {{ $updated.Format "2006-01-02T15:04:05Z07:00" }} - - {{ $ids := dict }} + {{ printf `<![CDATA[%s]]>` $title | safeHTML }} + {{ $updated }} {{ range $subpage := $subpages }} - {{ with partial "paige/authors.html" . }} - {{ range . }} - - {{ with .email }} - {{ . }} - {{ end }} - - {{ with .name }} - {{ . }} - {{ end }} - - {{ with .url }} - {{ . }} - {{ end }} - - {{ end }} - {{ end }} - {{ $content := .Content }} + {{ $id := "" }} + {{ $paramlink := and .Params.link (not (.Param "paige.feed.link_to_page")) | not | not }} + {{ $published := cond (not .PublishDate.IsZero) (.PublishDate.Format $format) "" }} + {{ $rights := site.Copyright | markdownify }} + {{ $summary := .Description | markdownify }} + {{ $title := .Title | markdownify }} + {{ $updated := .Lastmod.Format $format }} - {{ if $content }} - {{ if and .Params.link (not (.Param "paige.feed.link_to_page")) }} - {{ $link := or (.Param "paige.feed.page_link" | markdownify) "⏎" }} - {{ $footer := printf `

%s

` .Permalink .Title $link }} + {{ $link := cond $paramlink .Params.link .Permalink }} - {{ $content = print $content $footer }} - {{ end }} + {{ if and $content $paramlink }} + {{ $link := or (.Param "paige.feed.page_link" | markdownify) "⏎" }} + {{ $footer := printf `

%s

` .Permalink .Title $link }} - {{ printf "" $content | safeHTML }} + {{ $content = print $content $footer }} {{ end }} - {{ $id := "" }} + {{ if not $content }} + {{ $content = .Description | markdownify}} + {{ end }} {{ if .Params.id }} {{ $id = .Params.id }} {{ else if not .Date.IsZero }} - {{ $id = printf "tag:%s,%s:%s" (urls.Parse site.BaseURL).Host (.Date.Format "2006-01-02") (.Date.Format "2006-01-02T15:04:05Z07:00") }} + {{ $id = printf "tag:%s,%s:%s" (urls.Parse site.BaseURL).Host (.Date.Format "2006-01-02") (.Date.Format $format) }} {{ else }} {{ $id = .RelPermalink }} {{ end }} @@ -137,51 +125,66 @@ {{ end }} {{ $ids = merge (dict $id .RelPermalink) $ids }} - {{ $id }} - {{ range .OutputFormats }} - {{ if eq .Rel "alternate" }} - {{ printf `` (.Permalink | safeURL) .MediaType | safeHTML }} - {{ end }} + {{ if not $title }} + {{ warnf "layouts/_default/list.atom.xml: Page %s does not have a title" .RelPermalink }} {{ end }} - {{ range $t := .Translations }} - {{ range .OutputFormats }} - {{ if eq .Rel "alternate" }} - {{ printf `` (.Permalink | safeURL) $t.Lang .MediaType | safeHTML }} - {{ end }} - {{ end }} + {{ if .Lastmod.IsZero }} + {{ warnf "layouts/_default/list.atom.xml: Page %s does not have a modified date" .RelPermalink }} {{ end }} - {{ if and .Params.link (not (.Param "paige.feed.link_to_page")) }} - - {{ else }} - + {{ with partial "paige/authors.html" . }} + {{ range . }} + + {{ with .email }} + {{ . }} + {{ end }} + + {{ with .name }} + {{ . }} + {{ end }} + + {{ with .url }} + {{ . }} + {{ end }} + + {{ end }} {{ end }} - {{ if not .PublishDate.IsZero }} - {{ .PublishDate.Format "2006-01-02T15:04:05Z07:00" }} + {{ with $content }} + {{ printf "" . | safeHTML }} {{ end }} - {{ with site.Copyright }} - {{ printf "" (. | markdownify) | safeHTML }} + {{ $id }} + + {{ range $page.OutputFormats }} + {{ $rel := cond (eq .Permalink $page.Permalink) "self" .Rel }} + + {{ printf `` .Permalink $rel .MediaType | safeHTML }} {{ end }} - {{ with .Description }} - {{ printf "" (. | markdownify) | safeHTML }} + {{ range $t := $page.Translations }} + {{ range .OutputFormats }} + {{ printf `` .Permalink $t.Lang .Rel .MediaType | safeHTML }} + {{ end }} {{ end }} - {{ if not .Title }} - {{ warnf "layouts/_default/list.atom.xml: %s: Page %s does not have a title" .RelPermalink }} + {{ with $published }} + {{ . }} {{ end }} - {{ printf `<![CDATA[%s]]>` (.Title | markdownify) | safeHTML }} + {{ with $rights }} + {{ printf "" . | safeHTML }} + {{ end }} - {{ if .Lastmod.IsZero }} - {{ warnf "layouts/_default/list.atom.xml: Page %s does not have a modified date" .RelPermalink }} + {{ with $summary }} + {{ printf "" . | safeHTML }} {{ end }} - {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }} + {{ printf `<![CDATA[%s]]>` $title | safeHTML }} + + {{ $updated }}
{{ end }}
diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml index d9ac9ac2..37097db6 100644 --- a/layouts/_default/rss.xml +++ b/layouts/_default/rss.xml @@ -7,7 +7,7 @@ {{ $html := $page.AlternativeOutputFormats.Get "html" }} {{ $language := site.LanguageCode | default site.Language.Lang }} {{ $limit := site.Config.Services.RSS.Limit }} -{{ $link := $page.Permalink }} +{{ $link := ($page.AlternativeOutputFormats.Get "html").Permalink }} {{ $managingeditor := $page.Param "paige.feed.rss.managing_editor" }} {{ $pagetitle := $page.Title | markdownify | plainify }} {{ $sitetitle := site.Title | markdownify | plainify }} @@ -17,6 +17,12 @@ {{ $lastbuilddate := (partial "paige/changed.html" $page).Format $format }} +{{ $subpages = where $subpages "Params.paige.feed.hide_page" "ne" true }} + +{{ if ge $limit 0 }} + {{ $subpages = $subpages | first $limit }} +{{ end }} + {{ if and $pagetitle $sitetitle }} {{ if $page.IsHome }} {{ $title = $pagetitle }} @@ -29,14 +35,8 @@ {{ $title = $sitetitle }} {{ end }} -{{ $subpages = where $subpages "Params.paige.feed.hide_page" "ne" true }} - -{{ if ge $limit 0 }} - {{ $subpages = $subpages | first $limit }} -{{ end }} - {{ printf "" | safeHTML }} - + {{ with $copyright }} {{ . }} @@ -87,13 +87,11 @@ {{ end }} {{ end }} - {{ if $description }} - {{ if $paramlink }} - {{ $pagelink := or (.Param "paige.feed.page_link" | markdownify) "⏎" }} - {{ $footer := printf `

%s

` .Permalink $title $pagelink }} + {{ if and $description $paramlink }} + {{ $pagelink := or (.Param "paige.feed.page_link" | markdownify) "⏎" }} + {{ $footer := printf `

%s

` .Permalink $title $pagelink }} - {{ $description = print $description $footer }} - {{ end }} + {{ $description = print $description $footer }} {{ end }} {{ if not $description }} @@ -109,7 +107,7 @@ {{ else if not .Date.IsZero }} {{ $guid = printf "tag:%s,%s:%s" (urls.Parse site.BaseURL).Host (.Date.Format "2006-01-02") (.Date.Format "2006-01-02T15:04:05Z07:00") }} {{ else }} - {{ $guid = .RelPermalink }} + {{ $guid = .Permalink }} {{ $permalink = false }} {{ end }}