mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
taxonomy: add content toc to index toc in taxonomy pages #712
This commit is contained in:
parent
428b4b65dc
commit
dca1140273
2 changed files with 37 additions and 51 deletions
|
@ -9,23 +9,21 @@
|
||||||
<h1 id="{{ $title | plainify | anchorize }}">{{ $title }}</h1>
|
<h1 id="{{ $title | plainify | anchorize }}">{{ $title }}</h1>
|
||||||
{{- .Content }}
|
{{- .Content }}
|
||||||
{{- $lastCapital := "" }}
|
{{- $lastCapital := "" }}
|
||||||
{{- $terms := slice }}
|
{{- $pages := slice }}
|
||||||
{{- range .Data.Terms }}
|
{{- 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 }}
|
{{- $len := 0 }}
|
||||||
{{- range .Term.Pages }}
|
{{- range .Pages }}
|
||||||
{{- $c:=""}}{{/* count pages of term */}}
|
{{- $c:=""}}{{/* count pages of term */}}
|
||||||
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }}
|
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }}
|
||||||
{{- $len = add $len 1 }}
|
{{- $len = add $len 1 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if $len }}
|
{{- if $len }}
|
||||||
|
{{- $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 $capital }}
|
||||||
{{- if ne $lastCapital "" }}
|
{{- if ne $lastCapital "" }}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -34,9 +32,8 @@
|
||||||
<ul class="columnize">
|
<ul class="columnize">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $c:=""}}{{/* display terms of a taxonomy */}}
|
{{- $c:=""}}{{/* display terms of a taxonomy */}}
|
||||||
<li><a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .Term.Page) }}">{{ .Title }}</a> ({{ $len }})</li>
|
<li><a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .Term.Page) }}">{{ .Title }}</a> ({{ .Len }})</li>
|
||||||
{{- $lastCapital = $capital }}
|
{{- $lastCapital = $capital }}
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if ne $lastCapital "" }}
|
{{- if ne $lastCapital "" }}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -1,55 +1,44 @@
|
||||||
{{- if eq .Kind "taxonomy" }}
|
{{- if or (eq .Kind "taxonomy") (eq .Kind "term") }}
|
||||||
<nav id="TableOfContents">
|
|
||||||
<ul>
|
|
||||||
{{- $lastCapital := "" }}
|
{{- $lastCapital := "" }}
|
||||||
{{- $terms := slice }}
|
{{- $pages := slice }}
|
||||||
|
{{- if eq .Kind "taxonomy" }}
|
||||||
{{- range .Data.Terms }}
|
{{- 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 }}
|
{{- $len := 0 }}
|
||||||
{{- range .Term.Pages }}
|
{{- range .Pages }}
|
||||||
{{- $c:=""}}{{/* count pages of term */}}
|
{{- $c:=""}}{{/* count pages of term */}}
|
||||||
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }}
|
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }}
|
||||||
{{- $len = add $len 1 }}
|
{{- $len = add $len 1 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if $len }}
|
{{- if $len }}
|
||||||
{{- if ne $lastCapital $capital }}
|
{{- $pages = $pages| append (dict "Title" (default .Page.Data.Term .Page.Title) "Page" . "Len" $len )}}
|
||||||
<li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li>
|
|
||||||
{{- end }}
|
|
||||||
{{- $lastCapital = $capital }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</ul>
|
{{- else if eq .Kind "term" }}
|
||||||
</nav>
|
|
||||||
{{- else if eq .Kind "term" }}
|
|
||||||
{{- $lastCapital := "" }}
|
|
||||||
{{- $pages := slice }}
|
|
||||||
{{- range .Pages }}
|
{{- range .Pages }}
|
||||||
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }}
|
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableTagHiddenPages true) ) }}
|
||||||
{{- $pages = $pages | append (dict "Title" .Title "Page" . )}}
|
{{- $pages = $pages | append (dict "Title" .Title "Page" . )}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $toc_term := "" }}
|
{{- end }}
|
||||||
|
{{- $toc_pages := "" }}
|
||||||
{{- range sort $pages ".Title" }}
|
{{- range sort $pages ".Title" }}
|
||||||
{{- $capital := substr .Title 0 1 | upper }}
|
{{- $capital := substr .Title 0 1 | upper }}
|
||||||
{{- if ne $lastCapital $capital }}
|
{{- if ne $lastCapital $capital }}
|
||||||
{{- $toc_term = printf "%s <li><a href=\"#%s\">%s</a></li>\n" $toc_term ($capital | plainify | anchorize) $capital }}
|
{{- $toc_pages = printf "%s <li><a href=\"#%s\">%s</a></li>\n" $toc_pages ($capital | plainify | anchorize) $capital }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $lastCapital = $capital }}
|
{{- $lastCapital = $capital }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $toc := trim (partial "toc.html" .) " \n\r\t" }}
|
{{- $toc := trim (partial "toc.html" .) " \n\r\t" }}
|
||||||
{{- if and (not $toc) $toc_term }}
|
{{- if and (not $toc) $toc_pages }}
|
||||||
{{- $toc = printf "<nav id=\"TableOfContents\"></nav>" }}
|
{{- $toc = printf "<nav id=\"TableOfContents\"></nav>" }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if and $toc $toc_term }}
|
{{- if and $toc $toc_pages }}
|
||||||
{{- $toc = replaceRE "^(<nav id=\"TableOfContents\">)[\\s]*" "${1}\n <ul>\n" $toc }}
|
{{- $toc = replaceRE "^(<nav id=\"TableOfContents\">)[\\s]*" "${1}\n <ul>\n" $toc }}
|
||||||
{{- $toc = replaceRE "^(<nav id=\"TableOfContents\">[\\s]*<ul>)[\\s]*<ul>[\\n\\r]*" "${1}\n" $toc }}
|
{{- $toc = replaceRE "^(<nav id=\"TableOfContents\">[\\s]*<ul>)[\\s]*<ul>[\\n\\r]*" "${1}\n" $toc }}
|
||||||
{{- $toc = replaceRE "[\\s]*(</nav>)$" "\n </ul>\n${1}" $toc }}
|
{{- $toc = replaceRE "[\\s]*(</nav>)$" "\n </ul>\n${1}" $toc }}
|
||||||
{{- $toc = replaceRE "[ \\t]*</ul>[\\s]*(</ul>[\\s]*</nav>)$" " ${1}" $toc }}
|
{{- $toc = replaceRE "[ \\t]*</ul>[\\s]*(</ul>[\\s]*</nav>)$" " ${1}" $toc }}
|
||||||
{{- $toc = replaceRE "([ \\t]*</ul>[\\s]*</nav>)$" (printf "%s${1}" $toc_term) $toc }}
|
{{- $toc = replaceRE "([ \\t]*</ul>[\\s]*</nav>)$" (printf "%s${1}" $toc_pages) $toc }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ $toc | safeHTML }}
|
{{ $toc | safeHTML }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
|
|
Loading…
Reference in a new issue