From 411e3a599db6f66fa32513eae3fb5113f93ab463 Mon Sep 17 00:00:00 2001 From: Dmitry Kann Date: Fri, 13 Sep 2024 13:07:06 +0200 Subject: [PATCH] optimise/rearrange output formats for RSS, add RSS feed per section --- config/_default/hugo.yaml | 12 ++++----- cypress/e2e/site.cy.ts | 4 +-- .../_default/_feed-description.rss-all.xml | 1 + layouts/_default/_feed-description.rss.xml | 1 + layouts/_default/_feed-items.rss-all.xml | 3 +++ layouts/_default/_feed-items.rss.xml | 3 +++ layouts/_default/_feed-title.rss-all.xml | 1 + layouts/_default/_feed-title.rss.xml | 1 + layouts/_default/baseof.html | 7 ++++- .../{index.rss-all.xml => list.rss-all.xml} | 12 ++++----- .../_default/{index.rss.xml => list.rss.xml} | 12 ++++----- layouts/blog/subscribe.html | 2 +- layouts/post/_rss-item.xml | 27 +++++++++++++++++++ layouts/post/rss-item.xml | 27 ------------------- layouts/series/_feed-description.rss.xml | 1 + layouts/series/_feed-items.rss.xml | 3 +++ layouts/series/_feed-title.rss.xml | 1 + layouts/series/list.html | 23 ++++++++++++---- 18 files changed, 84 insertions(+), 57 deletions(-) create mode 100644 layouts/_default/_feed-description.rss-all.xml create mode 100644 layouts/_default/_feed-description.rss.xml create mode 100644 layouts/_default/_feed-items.rss-all.xml create mode 100644 layouts/_default/_feed-items.rss.xml create mode 100644 layouts/_default/_feed-title.rss-all.xml create mode 100644 layouts/_default/_feed-title.rss.xml rename layouts/_default/{index.rss-all.xml => list.rss-all.xml} (58%) rename layouts/_default/{index.rss.xml => list.rss.xml} (58%) create mode 100644 layouts/post/_rss-item.xml delete mode 100644 layouts/post/rss-item.xml create mode 100644 layouts/series/_feed-description.rss.xml create mode 100644 layouts/series/_feed-items.rss.xml create mode 100644 layouts/series/_feed-title.rss.xml diff --git a/config/_default/hugo.yaml b/config/_default/hugo.yaml index d6491429..95d300a8 100644 --- a/config/_default/hugo.yaml +++ b/config/_default/hugo.yaml @@ -117,24 +117,24 @@ taxonomies: videotrack: videotracks outputs: - # Only enable RSS generation on the home page. Also add RSS for All Languages and a redirect file - home: [HTML, RSS, RSS-ALL, REDIR] - section: [HTML] - taxonomy: [HTML] + # Only enable RSS generation on the homepage and section pages. Also add RSS for All Languages and a redirect file + home: [html, rss, rss-all, redir] + section: [html, rss] + taxonomy: [html] mediaTypes: text/bare: suffixes: outputFormats: - RSS-ALL: + rss-all: mediaType: application/rss+xml baseName: index-all isHTML: false isPlainText: false noUgly: true rel: alternate - REDIR: + redir: mediatype: text/bare baseName: _redirects isPlainText: true diff --git a/cypress/e2e/site.cy.ts b/cypress/e2e/site.cy.ts index e8d97096..27390dff 100644 --- a/cypress/e2e/site.cy.ts +++ b/cypress/e2e/site.cy.ts @@ -1,6 +1,4 @@ -/// - -import {Paths} from "../support/util"; +import { Paths } from '../support/util'; context('Site', () => { diff --git a/layouts/_default/_feed-description.rss-all.xml b/layouts/_default/_feed-description.rss-all.xml new file mode 100644 index 00000000..53933de4 --- /dev/null +++ b/layouts/_default/_feed-description.rss-all.xml @@ -0,0 +1 @@ +{{- .Site.Params.description -}} diff --git a/layouts/_default/_feed-description.rss.xml b/layouts/_default/_feed-description.rss.xml new file mode 100644 index 00000000..53933de4 --- /dev/null +++ b/layouts/_default/_feed-description.rss.xml @@ -0,0 +1 @@ +{{- .Site.Params.description -}} diff --git a/layouts/_default/_feed-items.rss-all.xml b/layouts/_default/_feed-items.rss-all.xml new file mode 100644 index 00000000..484b580c --- /dev/null +++ b/layouts/_default/_feed-items.rss-all.xml @@ -0,0 +1,3 @@ +{{- range first .Site.Params.rssLimit (where (where .Site.AllPages ".IsPage" true) "Type" "post") }} +{{- .Render "_rss-item" }} +{{- end -}} diff --git a/layouts/_default/_feed-items.rss.xml b/layouts/_default/_feed-items.rss.xml new file mode 100644 index 00000000..ba7f3581 --- /dev/null +++ b/layouts/_default/_feed-items.rss.xml @@ -0,0 +1,3 @@ +{{- range first .Site.Params.rssLimit (where .Site.RegularPages "Type" "post") }} +{{- .Render "_rss-item" }} +{{- end -}} diff --git a/layouts/_default/_feed-title.rss-all.xml b/layouts/_default/_feed-title.rss-all.xml new file mode 100644 index 00000000..dd6ba8a5 --- /dev/null +++ b/layouts/_default/_feed-title.rss-all.xml @@ -0,0 +1 @@ +{{- .Site.Title }} | {{ T "blog" -}} diff --git a/layouts/_default/_feed-title.rss.xml b/layouts/_default/_feed-title.rss.xml new file mode 100644 index 00000000..a6648e2c --- /dev/null +++ b/layouts/_default/_feed-title.rss.xml @@ -0,0 +1 @@ +{{- .Site.Title }} | {{ T "postsCurLang" }} | {{ T "blog" -}} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index e9849852..3a77fa08 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -19,7 +19,12 @@ {{ with .OutputFormats.Get "RSS" -}} - {{ printf "" .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} + {{ printf "" + .Rel + .MediaType.Type + .Permalink + ($.Title | default $.Site.Title) + | safeHTML }} {{ end -}} diff --git a/layouts/_default/index.rss-all.xml b/layouts/_default/list.rss-all.xml similarity index 58% rename from layouts/_default/index.rss-all.xml rename to layouts/_default/list.rss-all.xml index 1afde584..269ddad9 100644 --- a/layouts/_default/index.rss-all.xml +++ b/layouts/_default/list.rss-all.xml @@ -1,10 +1,10 @@ {{ printf "" | safeHTML }} - {{ .Site.Title }} | {{ T "blog" }} + {{ .Render "_feed-title" }} + {{ .Render "_feed-description" }} {{ .Permalink }} - {{ .Site.Params.description }} - Hugo {{ hugo.Version }} + Hugo {{- with .Site.LanguageCode }}{{ . }}{{ end }} {{- with .Site.Params.author }} noreply@yktoo.com ({{ . }}) @@ -12,9 +12,7 @@ {{- end }} {{- with .Site.Copyright }}{{ . }}{{ end }} {{- if not .Date.IsZero }}{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} - {{- with .OutputFormats.Get "RSS-ALL" }}{{ printf `` .Permalink .MediaType | safeHTML }}{{ end }} - {{- range first .Site.Params.rssLimit (where (where .Site.AllPages ".IsPage" true) "Type" "post") }} - {{- .Render "rss-item" }} - {{- end -}} + {{ with .OutputFormats.Get "rss-all" }}{{ printf `` .Permalink .MediaType | safeHTML }}{{ end }} +{{ .Render "_feed-items" }} diff --git a/layouts/_default/index.rss.xml b/layouts/_default/list.rss.xml similarity index 58% rename from layouts/_default/index.rss.xml rename to layouts/_default/list.rss.xml index dbbba890..73693ef0 100644 --- a/layouts/_default/index.rss.xml +++ b/layouts/_default/list.rss.xml @@ -1,10 +1,10 @@ {{ printf "" | safeHTML }} - {{ .Site.Title }} | {{ T "blog" }}: {{ T "postsCurLang" }} + {{ .Render "_feed-title" }} + {{ .Render "_feed-description" }} {{ .Permalink }} - {{ .Site.Params.description }} - Hugo {{ hugo.Version }} + Hugo {{- with .Site.LanguageCode }}{{ . }}{{ end }} {{- with .Site.Params.author }} noreply@yktoo.com ({{ . }}) @@ -12,9 +12,7 @@ {{- end }} {{- with .Site.Copyright }}{{ . }}{{ end }} {{- if not .Date.IsZero }}{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} - {{- with .OutputFormats.Get "RSS" }}{{ printf `` .Permalink .MediaType | safeHTML }}{{ end }} - {{- range first .Site.Params.rssLimit (where .Site.RegularPages "Type" "post") }} - {{- .Render "rss-item" }} - {{- end -}} + {{ with .OutputFormats.Get "rss" }}{{ printf `` .Permalink .MediaType | safeHTML }}{{ end }} +{{ .Render "_feed-items" }} diff --git a/layouts/blog/subscribe.html b/layouts/blog/subscribe.html index 5c1b901f..e5c6efd6 100644 --- a/layouts/blog/subscribe.html +++ b/layouts/blog/subscribe.html @@ -73,7 +73,7 @@
{{ T (print "posts_" .Language) }}
  • {{ T "postsAllLangs" }}
      - {{ with (.GetPage "/" ).OutputFormats.Get "RSS-ALL" }} + {{ with (.GetPage "/" ).OutputFormats.Get "rss-all" }}
    • {{ T "subscribeInFeedly" }}
    • {{ T "subscribeByRSS" }}
    • {{ end }} diff --git a/layouts/post/_rss-item.xml b/layouts/post/_rss-item.xml new file mode 100644 index 00000000..115805fb --- /dev/null +++ b/layouts/post/_rss-item.xml @@ -0,0 +1,27 @@ + + {{ partial "page-title" . }} + {{ .Permalink }}?utm_source=rss&utm_medium=feed_{{ .Language }}&utm_campaign=nix + {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} + noreply@yktoo.com ({{ .Params.author | default .Site.Params.author }}) + {{ .Permalink }} + + + {{- $page := . -}} + {{- with .Params.image -}} + {{- $url := . -}} + + {{- if findRE "^(/|http(s?)://)" $url -}} + {{- $url = absURL $url -}} + {{- else -}} + {{- $url = ($page.Resources.GetMatch $url).Permalink -}} + {{- end -}} + + {{- printf `Post image

      ` $url -}} + {{- end -}} + + {{- $summary := .Params.description | .RenderString | default .Summary | replaceRE "(?s)" "" | replaceRE "(?s)" "" }} + {{- if in $summary "

      " }}{{ $summary }}{{ else }}{{ printf "

      %s

      " $summary | safeHTML }}{{ end }} + + {{- printf `

      %s

      ` .Permalink (T "readOn") -}} +
      +
      diff --git a/layouts/post/rss-item.xml b/layouts/post/rss-item.xml deleted file mode 100644 index 074eb656..00000000 --- a/layouts/post/rss-item.xml +++ /dev/null @@ -1,27 +0,0 @@ - - {{ partial "page-title" . }} - {{ .Permalink }}?utm_source=rss&utm_medium=feed_{{ .Language }}&utm_campaign=nix - {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} - noreply@yktoo.com ({{ .Params.author | default .Site.Params.author }}) - {{ .Permalink }} - - - {{- $page := . -}} - {{- with .Params.image -}} - {{- $url := . -}} - - {{- if findRE "^(/|http(s?)://)" $url -}} - {{- $url = absURL $url -}} - {{- else -}} - {{- $url = ($page.Resources.GetMatch $url).Permalink -}} - {{- end -}} - - {{- printf `Post image

      ` $url -}} - {{- end -}} - - {{- $summary := .Params.description | .RenderString | default .Summary | replaceRE "(?s)" "" | replaceRE "(?s)" "" }} - {{- if in $summary "

      " }}{{ $summary }}{{ else }}{{ printf "

      %s

      " $summary }}{{ end }} - - {{- printf `

      %s

      ` .Permalink (T "readOn") -}} -
      -
      diff --git a/layouts/series/_feed-description.rss.xml b/layouts/series/_feed-description.rss.xml new file mode 100644 index 00000000..1decf9bd --- /dev/null +++ b/layouts/series/_feed-description.rss.xml @@ -0,0 +1 @@ +{{- T "blog" }}: {{ .Title }} — {{ .Params.description -}} diff --git a/layouts/series/_feed-items.rss.xml b/layouts/series/_feed-items.rss.xml new file mode 100644 index 00000000..36ca78e1 --- /dev/null +++ b/layouts/series/_feed-items.rss.xml @@ -0,0 +1,3 @@ +{{- range first .Site.Params.rssLimit .Pages }} +{{- .Render "_rss-item" }} +{{- end -}} diff --git a/layouts/series/_feed-title.rss.xml b/layouts/series/_feed-title.rss.xml new file mode 100644 index 00000000..5a9d1dfb --- /dev/null +++ b/layouts/series/_feed-title.rss.xml @@ -0,0 +1 @@ +{{- .Title }} | {{ T "blog" -}} diff --git a/layouts/series/list.html b/layouts/series/list.html index 10151d5e..871723e9 100644 --- a/layouts/series/list.html +++ b/layouts/series/list.html @@ -1,10 +1,23 @@ -{{ define "heading" }}

      {{ T "series" }}: {{ .Title }}

      {{ end }} +{{- define "title" }}{{ .Title | markdownify | plainify }} | {{ T "series" }} | {{ T "blog" }} | {{ .Site.Title }}{{ end }} -{{ define "secondary-navbar" }} -{{ partial "blog/navbar" . }} +{{- define "heading" }} +

      + + {{- T "blog" }}: {{ .Title -}} + + {{- with .OutputFormats.Get "RSS" }} + + + + {{- end }} +

      {{ end }} -{{ define "main" }} +{{- define "secondary-navbar" }} +{{- partial "blog/navbar" . }} +{{- end }} + +{{- define "main" }} {{- with .Params.description }}

      {{ . | $.RenderString }}

      @@ -28,4 +41,4 @@
      {{ template "_internal/pagination.html" . }}
      -{{ end }} +{{- end }}