From e5b269fb366c069653b59a38f6def73b03904d2f Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 6 Feb 2022 21:53:22 +0100 Subject: [PATCH] refactor: cleanup Atom feed template and remove CDATA (#195) --- layouts/_default/list.atom.xml | 78 +++++++++++++++---------------- layouts/partials/head/others.html | 15 +++--- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/layouts/_default/list.atom.xml b/layouts/_default/list.atom.xml index 1d909dd..f97a91e 100644 --- a/layouts/_default/list.atom.xml +++ b/layouts/_default/list.atom.xml @@ -1,51 +1,49 @@ -{{ printf `` | safeHTML }} {{/* ref: https://validator.w3.org/feed/docs/atom.html */}} +{{ printf `` | safeHTML }} Hugo {{- $title := .Site.Title -}} - {{- if not (eq .Kind "home") -}} + {{- if not (eq .Kind "home") }} {{- $title = printf `%s on %s` (partial "utils/title" .) $title -}} - {{- end -}} - {{ printf `<![CDATA[%s]]>` $title | safeHTML }} - {{ with .Site.Params.subtitle }} - {{ printf `` . | safeHTML }} - {{ end }} - {{ $output_formats := .OutputFormats }} - {{ range $output_formats -}} + {{- end }} + {{ trim ($title | plainify) "\n" }} + {{- with .Site.Params.subtitle }} + {{ trim (. | plainify) "\n" }} + {{- end }} + {{- $output_formats := .OutputFormats -}} + {{- range $output_formats -}} {{- $rel := (or (and (eq "atom" (.Name | lower)) "self") "alternate") -}} - {{ with $output_formats.Get .Name }} + {{- with $output_formats.Get .Name }} {{ printf `` .Permalink $rel .MediaType.Type .Name | safeHTML }} - {{- end -}} + {{- end }} {{- end }} {{ now.Format "2006-01-02T15:04:05-07:00" | safeHTML }} - Hugo - {{ with .Site.Params.GeekblogAuthor -}} - {{ with index $.Site.Data.authors . }} + {{- with .Site.Params.GeekblogAuthor -}} + {{- with index $.Site.Data.authors . }} {{ .name }} - {{ with .email }} + {{- with .email }} {{ . }} - {{ end -}} + {{- end }} - {{ end }} + {{- end }} {{- end }} {{ .Permalink }} {{- $pages := where .RegularPages "Type" "in" .Site.Params.mainSections -}} {{- if (eq .Kind "home") -}} {{- $pages = where .Site.RegularPages "Type" "in" .Site.Params.mainSections -}} {{- end -}} - {{- range $pages }} - {{ $page := . }} + {{- range $page := $pages }} - {{ printf `<![CDATA[%s]]>` (partial "utils/title" .) | safeHTML }} - + {{ trim (partial "utils/title" . | plainify) "\n" }} + {{ .Permalink }} - {{ with .Params.authors -}} - {{- range sort . -}} - {{ $author := index $.Site.Data.authors . }} + {{- with .Params.authors }} + {{- range sort . }} + {{- $author := index $.Site.Data.authors . }} {{ $author.name }} - {{- end -}} + {{- end }} {{- end }} {{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }} {{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }} @@ -54,20 +52,22 @@ {{- $featured := .Fill (printf "910x280 %s" (default "Smart" .Params.anchor)) -}} {{- $img = printf `%s
` $featured.Permalink $featured.Width $featured.Height (default (partial "utils/title" $page) .Params.description) -}} {{- end }} - {{ printf `` $img .Content | safeHTML }} - {{ with .Site.Taxonomies }} - {{ range $taxo,$_ := . }} - {{ with $page.Param $taxo }} - {{ $taxo_list := . }} - {{ with $.Site.GetPage (printf "/%s" $taxo) }} - {{ $taxonomy_page := . }} - {{ range $taxo_list }} + + {{ printf "%s%s" $img .Content | htmlEscape | safeHTML }} + + {{- with .Site.Taxonomies }} + {{- range $taxo,$_ := . }} + {{- with $page.Param $taxo }} + {{- $taxo_list := . -}} + {{- with $.Site.GetPage (printf "/%s" $taxo) }} + {{- $taxonomy_page := . -}} + {{- range $taxo_list }} - {{ end }} - {{ end }} - {{ end }} - {{ end }} - {{ end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} + {{- end }}
- {{ end }} + {{- end }}
diff --git a/layouts/partials/head/others.html b/layouts/partials/head/others.html index 3b9eee1..3e1ab23 100644 --- a/layouts/partials/head/others.html +++ b/layouts/partials/head/others.html @@ -65,15 +65,14 @@ href="{{ index (index .Site.Data.assets "custom.css") "src" | relURL }}" media="all" /> - - - -{{- with (.Site.GetPage "home").OutputFormats.Get "atom" }} - {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} +{{- with .OutputFormats.Get "html" }} + {{ printf `` .Permalink .Rel .MediaType.Type | safeHTML }} {{- end }} - -{{- with (.Site.GetPage "home").OutputFormats.Get "json" }} - {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} +{{- $output_formats := (.Site.GetPage "home").OutputFormats }} +{{- range $format := (.Site.GetPage "home").OutputFormats }} + {{- if not (eq $format.Rel "canonical") }} + {{ printf `` $format.Permalink $format.Rel $format.MediaType.Type $.Site.Title $format.Name | safeHTML }} + {{- end }} {{- end }} {{- if (default false $.Site.Params.GeekblogOverwriteHTMLBase) }}