gtm-test-site/themes/papercss-hugo-theme/layouts/partials/toc.html

21 lines
611 B
HTML
Raw Permalink Normal View History

2024-01-23 17:47:24 +03:00
{{ $headings := findRE "<h2.*?>(.|\n])+?</h2>" .Content }}
{{ if ge (len $headings) 2 }}
<div class="child-borders">
<div class="toc border" aria-labelledby="toc-heading">
<h2 id="toc-heading">Table of contents</h2>
<ol>
{{ range $headings }}
<li>
{{ $id := findRE "id=\".*\"" . }}
{{ $id = index $id 0 }}
{{ $id = strings.TrimPrefix "id=\"" $id }}
{{ $id = strings.TrimSuffix "\"" $id }}
<a href="#{{ $id }}">
{{ . | htmlUnescape | plainify }}
</a>
</li>
{{ end }}
</ol>
</div>
</div>
{{ end }}