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

27 lines
950 B
HTML
Raw Normal View History

<nav class="table-of-contents" id="TableOfContents">
<h2 class="table-of-contents__title">Table of Contents</h2>
{{- template "headings" (index .Fragments.Headings 0) }}
</nav>
{{- define "headings" }}
{{ if .Title -}}
{{ 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" $v }}
{{- 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" $v }}
{{- end }}
{{ print (strings.Repeat .Level "\t") }}</ol>
{{- end }}
{{- end }}
{{- end }}