Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zwbetz-gh/papercss-hugo-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/partials/toc.html')
-rw-r--r--layouts/partials/toc.html21
1 files changed, 21 insertions, 0 deletions
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
new file mode 100644
index 0000000..8879bd6
--- /dev/null
+++ b/layouts/partials/toc.html
@@ -0,0 +1,21 @@
+{{ $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 }} \ No newline at end of file