taxonomy: make arrow nav browse thru terms #742

This commit is contained in:
Sören Weber 2023-12-01 01:03:51 +01:00
parent a98fa1e0f8
commit 18061dbc06
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
9 changed files with 76 additions and 44 deletions

View file

@ -9,23 +9,8 @@
<h1 id="{{ $title | plainify | anchorize }}">{{ $title }}</h1>
{{- .Content }}
{{- $lastCapital := "" }}
{{- $pages := slice }}
{{- range .Data.Terms }}
{{- $len := 0 }}
{{- 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 }}
{{- $pages = $pages| append (dict "Title" (default (humanize .Page.Data.Term | strings.Title) .Page.Title) "Page" . "Len" $len )}}
{{- end }}
{{- if not .Page.Title }}
{{- warnf "%q: You have not given a 'title' in the frontmatter of your term page, the humanized term will be used instead" .Page.File.Filename }}
{{- end }}
{{- end }}
{{- range sort $pages ".Title" }}
{{- $pages := partialCached "partials/pageHelper/taxonomyPages.html" . . }}
{{- range $pages }}
{{- $capital := substr .Title 0 1 | upper }}
{{- if ne $lastCapital $capital }}
{{- if ne $lastCapital "" }}

View file

@ -11,13 +11,8 @@
<h1 id="{{ $title | plainify | anchorize }}">{{ $title }}</h1>
{{- .Content }}
{{- $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" . )}}
{{- end }}
{{- end }}
{{- range sort $pages ".Title" }}
{{- $pages := partialCached "partials/pageHelper/termPages.html" . . }}
{{- range $pages }}
{{- $capital := substr .Title 0 1 | upper }}
{{- if ne $lastCapital $capital }}
{{- if ne $lastCapital "" }}

View file

@ -0,0 +1,13 @@
{{- $collection := .collection }}
{{- $item := .item }}
{{- $found := false }}
{{- $result := "" }}
{{- range $collection }}
{{- if $found }}
{{- $result = .Page.Page }}
{{- break }}
{{- else if eq $item .Page.Page }}
{{- $found = true }}
{{- end }}
{{- end }}
{{- return $result }}

View file

@ -0,0 +1,12 @@
{{- $collection := .collection }}
{{- $item := .item }}
{{- $found := "" }}
{{- $result := "" }}
{{- range $collection }}
{{- if eq $item .Page.Page }}
{{- $result = $found }}
{{- break }}
{{- end }}
{{- $found = .Page.Page }}
{{- end }}
{{- return $result }}

View file

@ -0,0 +1,15 @@
{{- $pages := slice }}
{{- range .Data.Terms }}
{{- $len := 0 }}
{{- 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 }}
{{- $pages = $pages| append (dict "Title" (default (humanize .Page.Data.Term | strings.Title) .Page.Title) "Page" . "Len" $len )}}
{{- end }}
{{- end }}
{{- $pages = sort $pages ".Title" }}
{{- return $pages }}

View file

@ -0,0 +1,8 @@
{{- $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" . )}}
{{- end }}
{{- end }}
{{- $pages = sort $pages ".Title" }}
{{- return $pages }}

View file

@ -2,27 +2,12 @@
{{- $lastCapital := "" }}
{{- $pages := slice }}
{{- if eq .Kind "taxonomy" }}
{{- range .Data.Terms }}
{{- $len := 0 }}
{{- 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 }}
{{- $pages = $pages| append (dict "Title" (default (humanize .Page.Data.Term | strings.Title) .Page.Title) "Page" . "Len" $len )}}
{{- end }}
{{- end }}
{{- $pages = partialCached "partials/pageHelper/taxonomyPages.html" . . }}
{{- 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 }}
{{- $pages = partialCached "partials/pageHelper/termPages.html" . . }}
{{- end }}
{{- $toc_pages := "" }}
{{- range sort $pages ".Title" }}
{{- range $pages }}
{{- $capital := substr .Title 0 1 | upper }}
{{- if ne $lastCapital $capital }}
{{- $toc_pages = printf "%s <li><a href=\"#%s\">%s</a></li>\n" $toc_pages ($capital | plainify | anchorize) $capital }}

View file

@ -11,7 +11,16 @@
{{- $endarrow = "🡐" }}
{{- end }}
{{- $next := "" }}
{{- if or (ne $outputFormat "html") (not (.Scratch.Get "relearnNextPage")) }}
{{- if eq .Page.Kind "taxonomy" }}
{{- /* go to first term page */}}
{{- $pages := partialCached "partials/pageHelper/taxonomyPages.html" . . }}
{{- $next = (index $pages 0).Page.Page }}
{{- else if eq .Page.Kind "term" }}
{{- /* go to next term page */}}
{{- $taxonomy_page := .Site.GetPage .Data.Plural }}
{{- $pages := partialCached "partials/pageHelper/taxonomyPages.html" $taxonomy_page $taxonomy_page }}
{{- $next = partial "partials/pageHelper/next.html" (dict "collection" $pages "item" .) }}
{{- else if or (ne $outputFormat "html") (not (.Scratch.Get "relearnNextPage")) }}
{{- else }}
{{- $next = .Scratch.Get "relearnNextPage" }}
{{- end }}

View file

@ -12,7 +12,17 @@
{{- end }}
{{- $prev := "" }}
{{- if and (eq .RelPermalink .Site.Home.RelPermalink) (eq $outputFormat "html") }}
{{- else if or (ne $outputFormat "html") (not (.Scratch.Get "relearnPrevPage")) (eq .Page.Kind "taxonomy") (eq .Page.Kind "term") }}
{{- else if eq .Page.Kind "taxonomy" }}
{{- $prev = .Site.Home }}
{{- else if eq .Page.Kind "term" }}
{{- /* go to previous term page or taxonomy page if it is the first term */}}
{{- $taxonomy_page := .Site.GetPage .Data.Plural }}
{{- $pages := partialCached "partials/pageHelper/taxonomyPages.html" $taxonomy_page $taxonomy_page }}
{{- $prev = partial "partials/pageHelper/prev.html" (dict "collection" $pages "item" .) }}
{{- if not $prev }}
{{- $prev = $taxonomy_page }}
{{- end }}
{{- else if or (ne $outputFormat "html") (not (.Scratch.Get "relearnPrevPage")) }}
{{- $prev = .Site.Home }}
{{- else }}
{{- $prev = .Scratch.Get "relearnPrevPage" }}