_ 然后引入自定义的js文件,自定义js代码如下
let markbody = document.getElementById('hexo-blog-encrypt').firstChild;markbody.className="js-toc-content"; tocbot.init({ // Where to render the table of contents. tocSelector: '#toc', // Where to grab the headings to build the table of contents. contentSelector: '.js-toc-content', // Which headings to grab inside of the contentSelector element. headingSelector: 'h1, h2, h3, h4, h5, h6', // For headings inside relative or absolute positioned containers within content. hasInnerContainers: true,});
Issue
虽然不知道可不可行,我想在文章解密后加载其他js文件来生成目录,但是我不太清楚具体的 Callback 函数应该怎么写
Expected Behavior
在文章解密后成功加载js文件并执行
Actual Behavior
加载失败或者没有执行加载的js,没有生成TOC
Steps to Reproduce the Problem
_在自定义页面的MD文件最后通过js引入TOC 的js和CSS
_
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.min.js"></script>
_ 然后引入自定义的js文件,自定义js代码如下
let markbody = document.getElementById('hexo-blog-encrypt').firstChild;markbody.className="js-toc-content"; tocbot.init({ // Where to render the table of contents. tocSelector: '#toc', // Where to grab the headings to build the table of contents. contentSelector: '.js-toc-content', // Which headings to grab inside of the contentSelector element. headingSelector: 'h1, h2, h3, h4, h5, h6', // For headings inside relative or absolute positioned containers within content. hasInnerContainers: true,});
Specifications
主题用的是fluid,hexo和主题还有插件的版本在我测试的时候都是最新
另外似乎初始化的js中需要一个放生成TOC的div,我之前有尝试通过js创建一个并给他添加ID和class,但是在我想把他添加到一个指定位置的时候会报错,错误大概我猜测是由于加密解密造成的,例如我通过
document.getElementsByTagName('main')[0]
获取到第一个main标签(页面中有这个标签),并且用var声明一个变量maintag
等于他,然后再把我之前创建的div放到这个元素内但是在hexo g
之后我在网页的控制台看到heb.js报错,错误大概是‘maint’ undefined
这个样的,看起来像是我的变量不知道是什么原因被截断不完整了,所以才出现这个错误,我尝试修改变量名也不行,依旧会出现这个错误,想请教一下有没有什么解决办法,我应该怎么修改代码,谢谢(The version of the project, operating system, hardware etc.)