girde simple修改添加支持侧边栏目录

修改主题文件支持侧边栏目录 simple主题整体还行,但文章无侧边栏目录,一般写的技术性文章很长,就需要侧边栏目录和这个功能了,在网上搜了一下资料,对于前端小学生的我费了好长时间才搞定,记录一下过程。 1、修改post.ejs文件 head新增 <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script> 搜索<%- post.content %>复制一下代码覆盖copy 1 2 3 4 5 6 7 8 <div class="post-content-wrapper"> <div class="post-content" v-pre> <%- post.content %> </div> <div class="toc-container"> <%- post.toc %> </div> </div> 新增高亮js 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 <script> hljs.initHighlightingOnLoad() let mainNavLinks = document.querySelectorAll(".markdownIt-TOC a"); // This should probably be throttled. // Especially because it triggers during smooth scrolling. // https://lodash.com/docs/4.17.10#throttle // You could do like... // window.addEventListener("scroll", () => { // _.throttle(doThatStuff, 100); // }); // Only not doing it here to keep this Pen dependency-free. window.addEventListener("scroll", event => { let fromTop = window.scrollY; mainNavLinks.forEach((link, index) => { let section = document.getElementById(decodeURI(link.hash).substring(1)); let nextSection = null if (mainNavLinks[index + 1]) { nextSection = document....

创建: 2021-06-06 | 更新: 2024-04-29 | 字数: 349字 | 时长: 2分钟 | 作者:张三