summaryrefslogtreecommitdiff
path: root/toc.js
diff options
context:
space:
mode:
authorCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-05-10 14:46:07 -0500
committerCollin Williams <96917990+bluedragon1221@users.noreply.github.com>2026-05-10 14:46:07 -0500
commit0063bf9d2b2c416a6317cf45f68847b5720aab49 (patch)
tree2c8ab6fd181e481bf9faff65e6a80f4330a5ff54 /toc.js
parent85a2a330f729d70dfce1b81dc69ec15436a3d44c (diff)
updates and new post: 'Summer of PLT'
Diffstat (limited to 'toc.js')
-rw-r--r--toc.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/toc.js b/toc.js
new file mode 100644
index 0000000..633088a
--- /dev/null
+++ b/toc.js
@@ -0,0 +1,49 @@
+document.addEventListener("DOMContentLoaded", () => {
+ var tocDiv = document.createElement("div");
+ tocDiv.classList += "toc";
+ var toc = document.createElement("ul");
+
+ document.body.querySelectorAll('h1, h2, h3, h4, h5, h6').forEach(heading => {
+ var link = document.createElement('a');
+ link.setAttribute('href', '#'+heading.id.toLowerCase());
+ link.textContent = heading.textContent;
+
+ var li = document.createElement('li');
+ li.appendChild(link);
+
+ toc.appendChild(li);
+ });
+
+ tocDiv.append(toc);
+ document.body.prepend(tocDiv);
+
+ var styleBlock = document.createElement("style");
+ styleBlock.textContent = `
+ .toc {
+ position: fixed;
+ width: 17rem;
+ top: 32px;
+ left: calc(50vw - 37.5ch - 20rem);
+ padding-right: 0.75rem;
+ z-index: 1;
+
+ ul {
+ margin: 0;
+ padding-left: 1rem;
+ line-height: 1.4;
+ }
+
+ li {
+ margin-bottom: 0.35rem;
+ font-size: 1.1rem;
+ }
+ }
+
+ @media (max-width: 1000px) {
+ .toc {
+ display: none;
+ }
+ }
+ `;
+ document.head.append(styleBlock);
+}) \ No newline at end of file