前言

世界上除了学不完的知识,还有排不完的 bug。。
本篇记录自己在使用 Hexo+butterfly 主题过程中踩过的坑,所以本文可能有部分信息会过时,自行甄别,各取所需,但愿可以一直写下去吧。。。

1.文章一级目录无法跳转

打开网页按下f12,点击控制台查看报错

1
2
3
Uncaught TypeError: Cannot read properties of null (reading 'offsetTop')
at Object.getEleTop (utils.js:208:25)
at HTMLDivElement.<anonymous> (main.js:370:30)

image-20230325174530246

检查 “元素”,发现目录一级标题的'toc-link' 后没有正常生成 href 属性,因此无法实现跳转。

image-20230325174738186

出现此问题的原因是 markdown-it 插件的 bug,butterfly 主题的博客是由 markdown-it 渲染的,而这个插件并未渲染 heading 的 id 所以导致锚点失效,目录无法正常跳转。

解决方法是首先安装 markdown-it-named-headings 插件:

1
npm install markdown-it-named-headings --save

然后进入项目的根目录,修改根目录下 node_modules\hexo-renderer-markdown-it\lib\renderer.js 文件,在 renderer.js 中添加一行以使用此插件:

1
parser.use(require('markdown-it-named-headings'))

可能需要根据该文件中具体的代码格式进行适当修改

我的修改如下图:

image-20230325175320288

最后记得保存修改,然后Hexo三连即可解决此问题。

详细问题描述及解决方案参考 Hexo 博客踩坑 | blog (convivae.top)

2.hexo发生error:spawn failed错误的解决方法

https://s6.xinlal.com/2023/03/27/83Zt36MT.jpg

1
2
3
4
5
6
7
8
9
fatal: unable to access 'https://github.com/Refeain/Refeain.github.io/': Encountered end of file
FATAL {
err: Error: Spawn failed
at ChildProcess.<anonymous> (/usr/local/src/hexo/hanyubolg/node_modules/hexo-util/lib/spawn.js:51:21)
at ChildProcess.emit (events.js:376:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
code: 128
}
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

2.1 网络原因

关闭梯子等连接或者重启电脑,Hexo三连即可

2.2 因为git进行push或者hexo deploy的时候改变了一些.deploy_git文件下的内容,多余本地提交之类的导致

1
2
3
4
5
6
7
8
9
10
11
进入站点根目录
cd E:\hexo

删除git提交内容文件夹
rm -rf .deploy_git/

执行
git config --global core.autocrlf false

最后
hexo clean && hexo g && hexo d

2.3 有可能是你的git repo配置地址不正确,可以将http方式变更为ssh方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
进入站点根目录
cd /usr/local/src/hexo/...

删除git提交内容文件夹
vim _config.yml

修改
deploy:

type: git

repo: https://github.com/yourname/yourname.github.io.git -> git@github.com:Refeain/Refeain.github.io.git

branch: master

最后
hexo clean && hexo g && hexo d