From 43d1c68ef459d36cc7fc3266a326f9b9841ab41f Mon Sep 17 00:00:00 2001 From: Allan Chain Date: Tue, 7 Jan 2020 15:58:33 +0800 Subject: [PATCH] toc: add toc partial [newer impl] * gets toc fixed Signed-off-by: Aditya Telange <21258296+adityatelange@users.noreply.github.com> --- layouts/partials/toc.html | 84 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 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 00000000..f3146dc6 --- /dev/null +++ b/layouts/partials/toc.html @@ -0,0 +1,84 @@ +{{- $headers := findRE "(.|\n])+?" .Content -}} +{{- $has_headers := ge (len $headers) 1 -}} +{{- if $has_headers -}} + +{{- $largest := 6 -}} +{{- range $headers -}} +{{- $headerLevel := index (findRE "[1-4]" . 1) 0 -}} +{{- $headerLevel := len (seq $headerLevel) -}} +{{- if lt $headerLevel $largest -}} +{{- $largest = $headerLevel -}} +{{- end -}} +{{- end -}} + +{{- $firstHeaderLevel := len (seq (index (findRE "[1-4]" (index $headers 0) 1) 0)) -}} + +{{- $.Scratch.Set "bareul" slice -}} + +{{- else -}} + + +{{- end -}} +{{- end -}} + +{{- end -}} \ No newline at end of file