mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-18 10:50:24 +00:00
toc: invert toc file name usage #705
This commit is contained in:
parent
4a0417b4b0
commit
0cdef99463
5 changed files with 50 additions and 50 deletions
|
@ -1,3 +1,3 @@
|
|||
{{- $toc_content := partial "toc.html" . }}
|
||||
{{- $toc_content := partial "toc-id.html" . }}
|
||||
{{- $toc_content = strings.Replace $toc_content "id=\"TableOfContents\"" "class=\"TableOfContents\"" 1 }}
|
||||
{{- $toc_content | safeHTML }}
|
|
@ -1 +0,0 @@
|
|||
{{- .TableOfContents }}
|
48
layouts/partials/toc-id.html
Normal file
48
layouts/partials/toc-id.html
Normal file
|
@ -0,0 +1,48 @@
|
|||
{{- 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 "toc.html" . }}
|
||||
{{- end }}
|
|
@ -1,48 +1 @@
|
|||
{{- 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 "toc-content.html" . }}
|
||||
{{- end }}
|
||||
{{- .TableOfContents }}
|
Loading…
Reference in a new issue