taxonomy: fix toc generation for taxonomy and term pages #705

This commit is contained in:
Sören Weber 2023-10-30 00:44:41 +01:00
parent 215ab9c9d2
commit 7516352b52
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 68 additions and 4 deletions

View file

@ -2,8 +2,40 @@
<nav id="TableOfContents"> <nav id="TableOfContents">
<ul> <ul>
{{- $lastCapital := "" }} {{- $lastCapital := "" }}
{{- range .Data.Terms.Alphabetical }} {{- $terms := slice }}
{{- $capital := substr .Page.Title 0 1 | upper }} {{- range .Data.Terms }}
{{- $terms = $terms | append (dict "Title" (default .Page.Data.Term .Page.Title) "Term" . )}}
{{- end }}
{{- range sort $terms ".Title" }}
{{- $capital := substr .Title 0 1 | upper }}
{{- $len := 0 }}
{{- range .Term.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 }}
<li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li>
{{- end }}
{{- $lastCapital = $capital }}
{{- end }}
{{- end }}
</ul>
</nav>
{{- else if eq .Kind "term" }}
<nav id="TableOfContents">
<ul>
{{- $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" }}
{{- $capital := substr .Title 0 1 | upper }}
{{- if ne $lastCapital $capital }} {{- if ne $lastCapital $capital }}
<li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li> <li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li>
{{- end }} {{- end }}

View file

@ -2,8 +2,40 @@
<nav id="TableOfContents"> <nav id="TableOfContents">
<ul> <ul>
{{- $lastCapital := "" }} {{- $lastCapital := "" }}
{{- range .Data.Terms.Alphabetical }} {{- $terms := slice }}
{{- $capital := substr .Page.Title 0 1 | upper }} {{- range .Data.Terms }}
{{- $terms = $terms | append (dict "Title" (default .Page.Data.Term .Page.Title) "Term" . )}}
{{- end }}
{{- range sort $terms ".Title" }}
{{- $capital := substr .Title 0 1 | upper }}
{{- $len := 0 }}
{{- range .Term.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 }}
<li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li>
{{- end }}
{{- $lastCapital = $capital }}
{{- end }}
{{- end }}
</ul>
</nav>
{{- else if eq .Kind "term" }}
<nav id="TableOfContents">
<ul>
{{- $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" }}
{{- $capital := substr .Title 0 1 | upper }}
{{- if ne $lastCapital $capital }} {{- if ne $lastCapital $capital }}
<li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li> <li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li>
{{- end }} {{- end }}