cupper-hugo-theme/layouts/partials/toc.html
2019-02-26 10:16:01 -06:00

20 lines
570 B
HTML

{{ $headings := findRE "<h2.*?>(.|\n])+?</h2>" .Content }}
{{ if ge (len $headings) 2 }}
<nav class="toc" 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>
</nav>
{{ end }}