[gimp-web-devel/pat/bootstrap] theme: add toc partial to single.html layout



commit 3c29dd2fff6731b8c88e5c545c19e79e1e5271c2
Author: Pat David <patdavid gmail com>
Date:   Mon Sep 12 21:33:13 2022 -0500

    theme: add toc partial to single.html layout
    
    Single pages will now have a TOC auto-generated if they are above
    400 words in length.
    
    This can be controlled through the frontmatter of the post by
    setting `toc: false` if you don't want one.
    
    Right now it it default to show a TOC if there is no frontmatter.

 layouts/_default/single.html | 8 ++++++++
 layouts/partials/toc.html    | 8 ++++++++
 2 files changed, 16 insertions(+)
---
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 4736652..6471f6c 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -8,6 +8,14 @@
                        {{ .Title | markdownify }}
                </h1>
 
+               {{ if gt .WordCount 400  }}
+                       {{ if or (not (isset .Params "toc")) (.Params.toc) }}
+                                       <div class='col border-bottom border-top pt-2 my-3'>
+                                               {{ partial "toc.html" . }}
+                                       </div>
+                                       {{ end }}
+               {{ end }}
+
                {{ .Content }}
 
                {{ if .IsTranslated }}
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
new file mode 100644
index 0000000..580ea22
--- /dev/null
+++ b/layouts/partials/toc.html
@@ -0,0 +1,8 @@
+{{ with .TableOfContents }}
+  {{ if ne . "<nav id=\"TableOfContents\"></nav>" }}
+    <div class='h6 text-muted toctitle text-secondary'>Table of Contents</div>
+    <small>
+    {{ . }}
+    </small>
+  {{ end }}
+{{ end }}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]