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

github.com/yanlinlin82/simple-style.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.html44
1 files changed, 44 insertions, 0 deletions
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
new file mode 100644
index 0000000..7b4ac78
--- /dev/null
+++ b/layouts/partials/toc.html
@@ -0,0 +1,44 @@
+<!-- toc.html -->
+<!-- ignore empty links with + -->
+{{ $headers := findRE "<h[1-4].*?>(.|\n])+?</h[1-4]>" .Content }}
+<!-- at least one header to link to -->
+{{ if ge (len $headers) 1 }}
+{{ $h1_n := len (findRE "(.|\n])+?" .Content) }}
+{{ $re := (cond (eq $h1_n 0) "<h[2-4]" "<h[1-4]") }}
+{{ $renum := (cond (eq $h1_n 0) "[2-4]" "[1-4]") }}
+
+<!--Scrollspy-->
+<div class="toc">
+
+ <div class="page-header"><strong>目录</strong></div>
+
+ <div id="page-scrollspy" class="toc-nav">
+
+ {{ range $headers }}
+ {{ $header := . }}
+ {{ range first 1 (findRE $re $header 1) }}
+ {{ range findRE $renum . 1 }}
+ {{ $next_heading := (cond (eq $h1_n 0) (sub (int .) 1 ) (int . ) ) }}
+ {{ range seq $next_heading }}
+ <ul class="nav">
+ {{end}}
+ {{ $anchorId := (replaceRE ".* id=\"(.*?)\".*" "$1" $header ) }}
+ <li class="nav-item">
+ <a class="nav-link text-left" href="#{{ $anchorId }}">
+ {{ $header | plainify | htmlUnescape }}
+ </a>
+ </li>
+ <!-- close list -->
+ {{ range seq $next_heading }}
+ </ul>
+ {{ end }}
+ {{ end }}
+ {{ end }}
+ {{ end }}
+
+ </div>
+
+</div>
+<!--Scrollspy-->
+
+{{ end }} \ No newline at end of file