From a9f2619333dc7523a6af02930571da36f057a43b Mon Sep 17 00:00:00 2001 From: ycfxhsw Date: Mon, 10 May 2021 18:45:21 +0800 Subject: [PATCH] feat:add contents .Directory folding --- layouts/partials/toc.html | 49 +++++++++++++++++++++++++++++++++++++++ layouts/post/single.html | 5 ++++ 2 files changed, 54 insertions(+) create mode 100644 layouts/partials/toc.html diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html new file mode 100644 index 0000000..f1c4346 --- /dev/null +++ b/layouts/partials/toc.html @@ -0,0 +1,49 @@ + + +{{ $headers := findRE "(.|\n])+?" .Content }} + +{{ if ge (len $headers) 1 }} +{{ $h1_n := len (findRE "(.|\n])+?" .Content) }} +{{ $re := (cond (eq $h1_n 0) " +
+ +
+ + + + +
+ + {{ 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 }} + + {{ end }} + {{ end }} + {{ end }} + {{ end }} + +
+
+ +
+ + + +{{ end }} diff --git a/layouts/post/single.html b/layouts/post/single.html index 8cd32de..8749672 100644 --- a/layouts/post/single.html +++ b/layouts/post/single.html @@ -6,6 +6,11 @@ Back + + + {{ if .Site.Params.toc | default true }} + {{ partial "toc" . }} + {{ end }} {{ partial "article/article.html" . }}