|
36 | 36 | {{ content }} |
37 | 37 | </div> |
38 | 38 | </div> |
39 | | -<script> |
| 39 | +<!-- <script> |
40 | 40 | document.addEventListener("DOMContentLoaded", function() { |
41 | 41 | const toc = document.querySelector(".toc"); |
42 | 42 | const firstHeader = document.querySelector("h1"); |
|
69 | 69 | // Run on resize |
70 | 70 | window.addEventListener("resize", moveTOC); |
71 | 71 | }); |
| 72 | +</script> --> |
| 73 | +<script> |
| 74 | +document.addEventListener("DOMContentLoaded", function() { |
| 75 | + const toc = document.querySelector(".toc"); |
| 76 | + // Only grab the first h1 inside the main content div |
| 77 | + const firstHeader = document.querySelector(".content h1"); |
| 78 | + const originalParent = toc?.parentNode; |
| 79 | + const originalNextSibling = toc?.nextSibling; |
| 80 | + |
| 81 | + function moveTOC() { |
| 82 | + if (!toc || !firstHeader) return; |
| 83 | + |
| 84 | + if (window.innerWidth <= 800) { |
| 85 | + // Only move if it's not already after the header |
| 86 | + if (firstHeader.nextElementSibling !== toc) { |
| 87 | + firstHeader.insertAdjacentElement("afterend", toc); |
| 88 | + } |
| 89 | + } else { |
| 90 | + // Put back in the original sidebar location |
| 91 | + if (originalParent && toc.parentNode !== originalParent) { |
| 92 | + if (originalNextSibling) { |
| 93 | + originalParent.insertBefore(toc, originalNextSibling); |
| 94 | + } else { |
| 95 | + originalParent.appendChild(toc); |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + // Run once on load |
| 102 | + moveTOC(); |
| 103 | + |
| 104 | + // Throttle resize so it doesn't jump around too much |
| 105 | + let resizeTimer; |
| 106 | + window.addEventListener("resize", function() { |
| 107 | + clearTimeout(resizeTimer); |
| 108 | + resizeTimer = setTimeout(moveTOC, 150); |
| 109 | + }); |
| 110 | +}); |
72 | 111 | </script> |
73 | 112 |
|
74 | 113 | <style> |
|
0 commit comments