From 59ff58e15918b53f1ef8b921eaf1b263534e8264 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 23 Oct 2024 11:16:16 -0700 Subject: [PATCH] Break section template into first and descendent sections First section templates render the most recent $n yearly subsections as a list of articles. Descendent sections render just the content of those subsections. --- i18n/en.yaml | 6 +++ layouts/_default/list.html | 16 +++----- layouts/blog/list.html | 20 +++------- .../page/descendent_section.list.html | 13 +++++++ layouts/partials/page/first_section.list.html | 39 +++++++++++++++++++ layouts/partials/page/section_year_nav.html | 13 +++++++ 6 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 layouts/partials/page/descendent_section.list.html create mode 100644 layouts/partials/page/first_section.list.html create mode 100644 layouts/partials/page/section_year_nav.html diff --git a/i18n/en.yaml b/i18n/en.yaml index 5f80eef..5d80a99 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -6,3 +6,9 @@ draftNo: "NO" home: Home tableOfContents: Table of Contents + +# Title of section of a list page where years older than +# .Site.Params.blog.yearLimit are collapsed into a bulleted list. +olderPagesSectionTitle: Older + +yearsTagTitle: Years diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 641f3d0..8d428dc 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,13 +1,7 @@ {{ define "main" }} -
- - - {{- .Content -}} - - {{- range .Pages.ByTitle -}} - {{ .Render "page_summary" }} - {{- end -}} -
+ {{ if eq . .FirstSection }} + {{ partial "page/first_section.list.html" . }} + {{ else }} + {{ partial "page/descendent_section.list.html" . }} + {{ end }} {{ end }} diff --git a/layouts/blog/list.html b/layouts/blog/list.html index 52abe61..8d428dc 100644 --- a/layouts/blog/list.html +++ b/layouts/blog/list.html @@ -1,17 +1,7 @@ {{ define "main" }} -
- - - {{- with .Content }} -
{{ . }}
- {{ end -}} - - {{ range .Pages.ByDate.Reverse -}} - {{ if or (not .Draft) hugo.IsDevelopment }} - {{ .Render "page_summary" }} - {{ end }} - {{- end }} -
+ {{ if eq . .FirstSection }} + {{ partial "page/first_section.list.html" . }} + {{ else }} + {{ partial "page/descendent_section.list.html" . }} + {{ end }} {{ end }} diff --git a/layouts/partials/page/descendent_section.list.html b/layouts/partials/page/descendent_section.list.html new file mode 100644 index 0000000..0191d75 --- /dev/null +++ b/layouts/partials/page/descendent_section.list.html @@ -0,0 +1,13 @@ +
+ + + {{- .Content -}} + + {{ range .RegularPages.ByPublishDate -}} + {{ if or (not .Draft) hugo.IsDevelopment -}} + {{ .Render "page_summary" }} + {{ end }} + {{ end }} +
diff --git a/layouts/partials/page/first_section.list.html b/layouts/partials/page/first_section.list.html new file mode 100644 index 0000000..283dd98 --- /dev/null +++ b/layouts/partials/page/first_section.list.html @@ -0,0 +1,39 @@ +
+ + + {{/* Each page is a year section. */}} + {{- $yearPages := .Pages.ByPublishDate.Reverse -}} + {{- $yearLimit := math.Max ($.Site.Params.blog.yearLimit | default 5) 3 -}} + {{- $expandedYears := first $yearLimit $yearPages -}} + {{- $collapsedYears := after $yearLimit $yearPages -}} + + {{- + partial "page/section_year_nav.html" + (dict + "years" $expandedYears + "includeCollapsedYearItem" (gt (len $collapsedYears) 0) + ) + -}} + + {{- .Content -}} + + {{ range $expandedYears -}} +

{{ .Title }}

+ {{ range .RegularPagesRecursive.ByPublishDate.Reverse -}} + {{ if or (not .Draft) hugo.IsDevelopment -}} + {{ .Render "page_summary" }} + {{ end }} + {{ end }} + {{- end }} + + {{ with $collapsedYears -}} +

{{ i18n "olderPagesSectionTitle" }}

+ + {{ end }} +
diff --git a/layouts/partials/page/section_year_nav.html b/layouts/partials/page/section_year_nav.html new file mode 100644 index 0000000..bc2e14f --- /dev/null +++ b/layouts/partials/page/section_year_nav.html @@ -0,0 +1,13 @@ +{{- $years := .years -}} +{{- $includeCollapsedYearItem := .includeCollapsedYearItem -}} +