mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
taxonomy: add term page content toc to index toc #705
This commit is contained in:
parent
162554fd78
commit
73bfa82afd
1 changed files with 14 additions and 5 deletions
|
@ -25,8 +25,6 @@
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
{{- else if eq .Kind "term" }}
|
{{- else if eq .Kind "term" }}
|
||||||
<nav id="TableOfContents">
|
|
||||||
<ul>
|
|
||||||
{{- $lastCapital := "" }}
|
{{- $lastCapital := "" }}
|
||||||
{{- $pages := slice }}
|
{{- $pages := slice }}
|
||||||
{{- range .Pages }}
|
{{- range .Pages }}
|
||||||
|
@ -34,15 +32,26 @@
|
||||||
{{- $pages = $pages | append (dict "Title" .Title "Page" . )}}
|
{{- $pages = $pages | append (dict "Title" .Title "Page" . )}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- $toc_term := "" }}
|
||||||
{{- 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 }}
|
||||||
<li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li>
|
{{- $toc_term = printf "%s <li><a href=\"#%s\">%s</a></li>\n" $toc_term ($capital | plainify | anchorize) $capital }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $lastCapital = $capital }}
|
{{- $lastCapital = $capital }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</ul>
|
{{- $toc := trim (partial "toc.html" .) " \n\r\t" }}
|
||||||
</nav>
|
{{- if and (not $toc) $toc_term }}
|
||||||
|
{{- $toc = printf "<nav id=\"TableOfContents\"></nav>" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if and $toc $toc_term }}
|
||||||
|
{{- $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 "[\\s]*(</nav>)$" "\n </ul>\n${1}" $toc }}
|
||||||
|
{{- $toc = replaceRE "[ \\t]*</ul>[\\s]*(</ul>[\\s]*</nav>)$" " ${1}" $toc }}
|
||||||
|
{{- $toc = replaceRE "([ \\t]*</ul>[\\s]*</nav>)$" (printf "%s${1}" $toc_term) $toc }}
|
||||||
|
{{- end }}
|
||||||
|
{{ $toc | safeHTML }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- partial "toc.html" . }}
|
{{- partial "toc.html" . }}
|
||||||
{{- end }}
|
{{- end }}
|
Loading…
Reference in a new issue