From 5d37a104c4a413df04e4b0fbcfe6cb026cd52136 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Fri, 16 May 2025 15:03:14 +0800 Subject: perf: replace tocbot with statically generated toc Generate TOC with Hugo's built-in {{ .TableOfContents }} and add minimal script to implement collapsible list and active styles. Encapsulate TOC as a component where all JavaSript and CSS is in one place with HTML. Configure markup. Former-commit-id: 4b4629edb733d5ebd6485755fd2f63b0457f62c8 --- layouts/_default/single.html | 14 ---- layouts/partials/components/toc.html | 130 +++++++++++++++++++++++++++++++++++ layouts/posts/single.html | 16 +---- 3 files changed, 131 insertions(+), 29 deletions(-) create mode 100644 layouts/partials/components/toc.html (limited to 'layouts') diff --git a/layouts/_default/single.html b/layouts/_default/single.html index bfe80ad5..d23ceed4 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -7,24 +7,10 @@
- {{ if .Params.toc }} -
- {{ end }} {{ .Site.Params.postHeaderContent | safeHTML }} {{ .Content }}
- - - {{ partial "footer.html" . }} {{ end }} diff --git a/layouts/partials/components/toc.html b/layouts/partials/components/toc.html new file mode 100644 index 00000000..660d4bb2 --- /dev/null +++ b/layouts/partials/components/toc.html @@ -0,0 +1,130 @@ +
{{ .TableOfContents }}
+ + diff --git a/layouts/posts/single.html b/layouts/posts/single.html index bb0daca8..e6dc6006 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -37,9 +37,7 @@
- {{ if .Params.toc }} -
- {{ end }} + {{ if .Params.toc }}{{ partial "components/toc" . }}{{ end }} {{ .Site.Params.postHeaderContent | safeHTML }} {{ .Content }} {{ if eq .Site.Language.Lang "zh" }} @@ -82,17 +80,5 @@ {{ else }}
  • {{ end }} - - - - {{ end }} -- cgit v1.2.3