Hexo异常


本文记录常见Hexo异常和解决方案

Cannot set property ‘lastIndex’ of undefined

INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: Cannot set property 'lastIndex' of undefined
    at highlight (/Users/chenshang/Blog/node_modules/highlight.js/lib/highlight.js:579:35)
    at /Users/chenshang/Blog/node_modules/highlight.js/lib/highlight.js:629:21
    at Array.forEach (<anonymous>)
    at Object.highlightAuto (/Users/chenshang/Blog/node_modules/highlight.js/lib/highlight.js:628:62)
    at /Users/chenshang/Blog/node_modules/hexo-util/lib/

    ......

修改配置文件_config.yml,注意不是主题里面的配置文件!把auto_detect设置为false,即可解决。

Hexo关于categories名字大写导致404问题

关于hexo-renderer-markdown-it引起的一级目录无法跳转的错误

hexo-renderer-marked 是 Hexo 默认的 Markdown 的渲染器,针对于普通的 Markdown 的文章书写,该渲染器已经足够,但是由于不支持 Mathjax,不支持插件扩展,不支持 emoji 表情,所以该渲染器也是介绍的渲染器中功能最弱的。

于是后面安装了 hexo-renderer-markdown-it 这个渲染器,支持 Mathjax 语法(支持不太好),支持 Markdown 以及 CommonMark 语法,渲染速度比 hexo-renderer-marked 快,支持插件配置,支持标题带安全的 id 信息,支持脚注(上标,下标,下划线)。

但是这个工具会引起一级目录跳转总是回到顶部而不是对应的标题。于是想要改回 hexo-renderer-marked ,可是 这个原生的插件会导致 ![图片](目录/图片) 这种写法下图片无法显示,只能转而使用 <img src="目录/图片"> 这种形式,而我文章中已经有大量这样语法写的图片展示了,要是改变写法估计够呛了。

于是最终百度查到了 hexo-renderer-markdown-it-plus 这个插件,看名字就是 hexo-renderer-markdown-it 的升级版,支持 Katex 插件并默认启用,默认启用插件列表:markdown-it-emojimarkdown-it-submarkdown-it-supmarkdown-it-deflistmarkdown-it-abbrmarkdown-it-footnotemarkdown-it-insmarkdown-it-mark@iktakahiro/markdown-it-katexmarkdown-it-toc-and-anchor

试用了一下,果然所有问题都解决了,目录也能正常跳转了,图片也能正常显示了,完美。

安装 hexo-renderer-markdown-it-plus 之前,先把hexo-renderer-markedhexo-renderer-markdown-it都卸载干净

npm uninstall hexo-renderer-marked -s
npm uninstall hexo-renderer-markdown-it -s
npm install hexo-renderer-markdown-it-plus -s

hexo 消除 LaTeX-incompatible input and strict mode is set to ‘warn’

我猜测应该是开启了 hexo-renderer-markdown-it-plus 作为渲染器并且用 katex 进行公式解析,用 vscode 等支持正则搜索的工具搜索博客文章,输入 $.[\u4e00-\u9fa5]+.$ 然后尝试定位,但是由于公式语法首尾是一样的所以定位不一定准。另外这个报错是对每个字符都会报错,所以可以尝试把相关的中文连起来搜索定位。


评论
  目录