diff options
author | FFRaycoder <nn_201312@163.com> | 2020-09-01 14:26:22 +0300 |
---|---|---|
committer | FFRaycoder <nn_201312@163.com> | 2020-09-01 14:26:22 +0300 |
commit | c8f3bbc976560ae62d38032bb70051254ee483da (patch) | |
tree | 494183d6706dcad1e1512715f12d9809ef637b00 | |
parent | 2e08e31a5f73a141138e05e3100e0c7c57f6c71e (diff) |
feat: better toc
我真的不想被人骂了,祖安人跑来GitHub骂人?
#8
-rw-r--r-- | layouts/partials/components/post/toc.html | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/layouts/partials/components/post/toc.html b/layouts/partials/components/post/toc.html index 191519f..f7cb474 100644 --- a/layouts/partials/components/post/toc.html +++ b/layouts/partials/components/post/toc.html @@ -1,6 +1,4 @@ {{ if .Params.toc | default .Site.Params.enableToc }}
-
-
<!-- ignore empty links with + -->
{{ $headers := findRE "<h[1-4].*?>(.|\n])+?</h[1-4]>" .Content }}
<!-- at least one header to link to -->
@@ -16,8 +14,22 @@ </h4>
</div>
<ul id="article-index" class="index-ul">
- {{ .TableOfContents }}
+ {{ 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 . ) ) }}
+ {{ $anchorId := (replaceRE ".* id=\"(.*?)\".*" "$1" $header ) }}
+ <a href="#{{ $anchorId }}">
+ <li style="padding-left:23px" class="">
+ <i class="ri-checkbox-blank-circle-line"></i>
+ {{ $header | plainify | htmlUnescape }}
+ </li>
+ </a>
+ {{ end }}
+ {{ end }}
+ {{ end }}
</ul>
</div>
{{ end }}
-{{- end -}}
+{{- end -}}
\ No newline at end of file |