trwnh.com/unified.test.hugo/layouts/partials/components/table-of-contents.html

52 lines
No EOL
1.8 KiB
HTML

{{/* {{- $startLevel := 2 -}}
{{- $endLevel := 3 -}}
{{ with .Param "markup.tableOfContents.startLevel" }}
{{- $startLevel = . }}
{{- end }}
{{ with .Param "markup.tableOfContents.endLevel" }}
{{- $endLevel = . }}
{{- end -}}
{{ debug.Dump ($startLevel) }}
{{ debug.Dump ($endLevel) }}
<nav class="table-of-contents" id="TableOfContents">
<h2 class="table-of-contents__title">Table of Contents</h2>
{{- template "headings" (dict "headings" (index .Fragments.Headings 0) "startLevel" $startLevel "endLevel" $endLevel) }}
</nav>
{{- define "headings" }}
{{- $startLevel := .startLevel -}}
{{- $endLevel := .endLevel -}}
{{- with .headings }}
{{- if and (.Title) (ge .Level $startLevel) (le .Level $endLevel) -}}
{{ print (strings.Repeat (sub .Level 1) "\t") }}<li data-depth="{{sub .Level 1}}">
{{ print (strings.Repeat (sub .Level 1) "\t") }}<a href="#{{.ID}}">{{.Title | htmlUnescape}}</a>
{{- if .Headings }}
{{ print (strings.Repeat (sub .Level 1) "\t") }}<ol data-depth="{{sub .Level 1}}">
{{- range $k, $v := .Headings }}
{{- template "headings" (dict "headings" $v "startLevel" $startLevel "endLevel" $endLevel) }}
{{- end }}
{{ print (strings.Repeat (sub .Level 1) "\t") }}</ol>
{{- end }}
{{ print (strings.Repeat (sub .Level 1) "\t") }}</li>
{{- else }}
{{- if .Headings -}}
{{ print (strings.Repeat .Level "\t") }}<ol data-depth="{{.Level}}">
{{- range $k, $v := .Headings }}
{{- template "headings" (dict "headings" $v "startLevel" $startLevel "endLevel" $endLevel) }}
{{- end }}
{{ print (strings.Repeat .Level "\t") }}</ol>
{{- end }}
{{- end }}
{{- end }}
{{- end }} */}}
{{
(
replace
.TableOfContents
"<nav id=\"TableOfContents\">\n"
"<nav class=\"table-of-contents\" id=\"TableOfContents\">\n<h2 class=\"table-of-contents__title\">Table of Contents</h2>\n"
)
| safeHTML
}}