mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
toc: simplify user-defined toc generation #705
dry out too much duplication in the theme
This commit is contained in:
parent
73d8491b81
commit
589ef2040d
4 changed files with 6 additions and 52 deletions
4
exampleSite/layouts/partials/toc-content.html
Normal file
4
exampleSite/layouts/partials/toc-content.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{- partial "shortcodes/piratify.html" (dict
|
||||
"page" .
|
||||
"pagefield" "TableOfContents"
|
||||
) }}
|
|
@ -1,51 +0,0 @@
|
|||
{{- if eq .Kind "taxonomy" }}
|
||||
<nav id="TableOfContents">
|
||||
<ul>
|
||||
{{- $lastCapital := "" }}
|
||||
{{- $terms := slice }}
|
||||
{{- 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 }}
|
||||
<li><a href="#{{ $capital | plainify | anchorize }}">{{ $capital }}</a></li>
|
||||
{{- end }}
|
||||
{{- $lastCapital = $capital }}
|
||||
{{- end }}
|
||||
</ul>
|
||||
</nav>
|
||||
{{- else }}
|
||||
{{- partial "shortcodes/piratify.html" (dict
|
||||
"page" .
|
||||
"pagefield" "TableOfContents"
|
||||
) }}
|
||||
{{- end }}
|
1
layouts/partials/toc-content.html
Normal file
1
layouts/partials/toc-content.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{- .TableOfContents }}
|
|
@ -44,5 +44,5 @@
|
|||
</ul>
|
||||
</nav>
|
||||
{{- else }}
|
||||
{{- .TableOfContents }}
|
||||
{{- partial "toc-content.html" . }}
|
||||
{{- end }}
|
Loading…
Reference in a new issue