|
1 | 1 | <html> |
2 | 2 | <head> |
3 | 3 | <%- include('./includes/head', { siteTitle: `${post.title} | ${themeConfig.siteName}` }) %> |
| 4 | + <meta name="description" content="<%- post.description %>" /> |
| 5 | + <meta name="keywords" content="<%- post.tags.map(tag => tag.name).join(',') %>" /> |
| 6 | + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css"> |
| 7 | + <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script> |
4 | 8 | </head> |
5 | 9 | <body> |
6 | 10 | <div class="main"> |
|
62 | 66 | <%- include('./includes/footer') %> |
63 | 67 | </div> |
64 | 68 | </div> |
| 69 | + |
| 70 | + <script> |
| 71 | + hljs.initHighlightingOnLoad() |
| 72 | +
|
| 73 | + let mainNavLinks = document.querySelectorAll(".markdownIt-TOC a"); |
| 74 | +
|
| 75 | + // This should probably be throttled. |
| 76 | + // Especially because it triggers during smooth scrolling. |
| 77 | + // https://lodash.com/docs/4.17.10#throttle |
| 78 | + // You could do like... |
| 79 | + // window.addEventListener("scroll", () => { |
| 80 | + // _.throttle(doThatStuff, 100); |
| 81 | + // }); |
| 82 | + // Only not doing it here to keep this Pen dependency-free. |
| 83 | +
|
| 84 | + window.addEventListener("scroll", event => { |
| 85 | + let fromTop = window.scrollY; |
| 86 | +
|
| 87 | + mainNavLinks.forEach((link, index) => { |
| 88 | + let section = document.getElementById(decodeURI(link.hash).substring(1)); |
| 89 | + let nextSection = null |
| 90 | + if (mainNavLinks[index + 1]) { |
| 91 | + nextSection = document.getElementById(decodeURI(mainNavLinks[index + 1].hash).substring(1)); |
| 92 | + } |
| 93 | + if (section.offsetTop <= fromTop) { |
| 94 | + if (nextSection) { |
| 95 | + if (nextSection.offsetTop > fromTop) { |
| 96 | + link.classList.add("current"); |
| 97 | + } else { |
| 98 | + link.classList.remove("current"); |
| 99 | + } |
| 100 | + } else { |
| 101 | + link.classList.add("current"); |
| 102 | + } |
| 103 | + } else { |
| 104 | + link.classList.remove("current"); |
| 105 | + } |
| 106 | + }); |
| 107 | + }); |
| 108 | +
|
| 109 | + </script> |
65 | 110 | </body> |
66 | 111 | </html> |
0 commit comments