From 4645e7b877f6d8a7a14b9f85c6ebf46e6cff88c8 Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me>
Date: Mon, 16 Oct 2023 22:04:31 -0400
Subject: [PATCH] Added rendering of Table of Contents

---
 CHANGELOG.md                               |  1 +
 assets/css/main.css                        | 33 ++++++++++++++++++++++
 layouts/partials/articles_for_section.html |  1 +
 layouts/partials/toc.html                  |  1 +
 4 files changed, 36 insertions(+)
 create mode 100644 layouts/partials/toc.html

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 690e7e3a7..b8fcfb0c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@
     modification of code. See updated `README.me`.
 * Added MathJax support for rendering Latex and math.
 * Added support for PseudocodeJS for rendering beautiful, standard, pseudocode.
+* Table of contents will now render if frontmatter `toc` is set to `true`.
 
 ## 1.1.0
 
diff --git a/assets/css/main.css b/assets/css/main.css
index 7d97cab51..cdb955547 100644
--- a/assets/css/main.css
+++ b/assets/css/main.css
@@ -629,3 +629,36 @@ section > .container > .row > .col {
     width: 100%;
   }
 }
+
+/* Styling for table of contents */
+
+#TableOfContents {
+    border: 1px black solid;
+    display: inline-block;
+    padding-right: 40px;
+    padding-top: 5px;
+    padding-bottom: 5px;
+    background-color: floralwhite;
+    width: 400px;
+    margin-left: 40px;
+    margin-bottom: 10px;
+}
+
+#TableOfContents ul {
+    padding-inline-start: 40px;
+}
+
+#TableOfContents ul,
+#TableOfContents ol {
+    padding-left: 40px;
+    margin-bottom: 10px;
+}
+
+/* Adjusts links within the same page so as to not be covered by the header menu */
+
+:target::before {
+  content: "";
+  display: block;
+  height: calc(1em + var(--ifm-navbar-height)); /* fixed header height*/
+  margin: calc(-1em * (1em + var(--ifm-navbar-height))) 0 0; /* negative fixed header height */
+}
diff --git a/layouts/partials/articles_for_section.html b/layouts/partials/articles_for_section.html
index 880187a3b..1531be9ce 100644
--- a/layouts/partials/articles_for_section.html
+++ b/layouts/partials/articles_for_section.html
@@ -3,6 +3,7 @@
 {{ range $index, $element := $paginator.Pages }}
   <article class='post'>
     {{ partial "post_header_list.html" . }}
+    {{ partial "toc.html" . }}
     <section class='post-content'>
       {{.Content }}
     </section>
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
new file mode 100644
index 000000000..64546ec06
--- /dev/null
+++ b/layouts/partials/toc.html
@@ -0,0 +1 @@
+{{ .TableOfContents }}
-- 
GitLab