From dca11402735539cafb17eead7a75723e39c313b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Fri, 3 Nov 2023 23:11:00 +0100 Subject: [PATCH] taxonomy: add content toc to index toc in taxonomy pages #712 --- layouts/_default/taxonomy.html | 29 ++++++++---------- layouts/partials/toc-id.html | 55 ++++++++++++++-------------------- 2 files changed, 35 insertions(+), 49 deletions(-) diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index 2f3e9d41e09..ca04cf9e30d 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -9,34 +9,31 @@

{{ $title }}

{{- .Content }} {{- $lastCapital := "" }} -{{- $terms := slice }} +{{- $pages := slice }} {{- range .Data.Terms }} - {{- $terms = $terms | append (dict "Title" (default .Page.Data.Term .Page.Title) "Term" . )}} - {{- if not .Page.Title }} - {{- warnf "%q: You have not given a 'title' in the frontmatter of your term page, the urlized title will be used instead" .Page.File.Filename }} - {{- end }} -{{- end }} -{{- range sort $terms ".Title" }} - {{- $capital := substr .Title 0 1 | upper }} {{- $len := 0 }} - {{- range .Term.Pages }} + {{- range .Pages }} {{- $c:=""}}{{/* count pages of term */}} {{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }} {{- $len = add $len 1 }} {{- end }} {{- end }} {{- if $len }} - {{- if ne $lastCapital $capital }} - {{- if ne $lastCapital "" }} + {{- $pages = $pages| append (dict "Title" (default .Page.Data.Term .Page.Title) "Page" . "Len" $len )}} + {{- end }} +{{- end }} +{{- range sort $pages ".Title" }} + {{- $capital := substr .Title 0 1 | upper }} + {{- if ne $lastCapital $capital }} + {{- if ne $lastCapital "" }} - {{- end }} + {{- end }}

{{ $capital }}

diff --git a/layouts/partials/toc-id.html b/layouts/partials/toc-id.html index efee626f091..c974c64c7f2 100644 --- a/layouts/partials/toc-id.html +++ b/layouts/partials/toc-id.html @@ -1,55 +1,44 @@ -{{- if eq .Kind "taxonomy" }} - -{{- else if eq .Kind "term" }} - {{- $lastCapital := "" }} - {{- $pages := slice }} - {{- range .Pages }} - {{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }} - {{- $pages = $pages | append (dict "Title" .Title "Page" . )}} + {{- else if eq .Kind "term" }} + {{- range .Pages }} + {{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }} + {{- $pages = $pages | append (dict "Title" .Title "Page" . )}} + {{- end }} {{- end }} {{- end }} - {{- $toc_term := "" }} + {{- $toc_pages := "" }} {{- range sort $pages ".Title" }} {{- $capital := substr .Title 0 1 | upper }} {{- if ne $lastCapital $capital }} - {{- $toc_term = printf "%s
  • %s
  • \n" $toc_term ($capital | plainify | anchorize) $capital }} + {{- $toc_pages = printf "%s
  • %s
  • \n" $toc_pages ($capital | plainify | anchorize) $capital }} {{- end }} {{- $lastCapital = $capital }} {{- end }} {{- $toc := trim (partial "toc.html" .) " \n\r\t" }} - {{- if and (not $toc) $toc_term }} + {{- if and (not $toc) $toc_pages }} {{- $toc = printf "" }} {{- end }} - {{- if and $toc $toc_term }} + {{- if and $toc $toc_pages }} {{- $toc = replaceRE "^()$" " ${1}" $toc }} - {{- $toc = replaceRE "([ \\t]*[\\s]*)$" (printf "%s${1}" $toc_term) $toc }} + {{- $toc = replaceRE "([ \\t]*[\\s]*)$" (printf "%s${1}" $toc_pages) $toc }} {{- end }} {{ $toc | safeHTML }} {{- else }}