hexo常见问题解决

hexo

问题

1. page下怎么放置多篇文章?

手动进行文档分类,就是将md文件放到_post文件夹下不同的categories文件夹下,hexo g的时候,还是能够生成的。但是如果使用hexo new命令来创建的话,还是没有找到自动放到对应categories文件夹的方法

2. _post目录下面的文章怎么用目录进行归类?

使用Hexo的内建归档categories
作者:孔晨皓
链接:https://www.zhihu.com/question/33324071/answer/149081141
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

思路:在script里写个遍历所有post的脚本筛选出你要简历目录的文章(根据tag或者categories)然后生成一个页面到 source/xxx.md 或者source/xxx.html你可以把这个脚本注册到生成文章前,这样就会跟着post一起渲染。
具体步骤:博客根目录建script文件夹里面新建

1
2
3
4
5
6
7
8
9
10
xxx.jshexo.extend.generator.register('name',
function(locals) {
return {
path: './source/xxx.md',
data: function(){
var posts = locals.posts.sort('-date'); var d = ""; posts.forEach(function(post) { //在这里筛选 然后把信息写入d变量
});
return d;//往xxx.md写入d
}
};});

看下官方文档很容易明白的按照上面的改改就行—手机没排版,没测试,不过该思路可行如果想高端点就把这个改成插件,也一样的

3. TypeError: Cannot set property ‘lastIndex’ of undefined 错误解决

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
$ hexo g
INFO Start processing
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
TypeError: Cannot set property 'lastIndex' of undefined
at highlight (F:\blog\init\node_modules\highlight.js\lib\highlight.js:511:35)
at F:\blog\init\node_modules\highlight.js\lib\highlight.js:561:21
at Array.forEach (<anonymous>)
at Object.highlightAuto (F:\blog\init\node_modules\highlight.js\lib\highlight.js:560:40)
at F:\blog\init\node_modules\hexo-util\lib\highlight.js:117:25
at highlight (F:\blog\init\node_modules\hexo-util\lib\highlight.js:120:7)
at highlightUtil (F:\blog\init\node_modules\hexo-util\lib\highlight.js:22:14)
at F:\blog\init\node_modules\hexo\lib\plugins\filter\before_post_render\backtick_code_block.js:62:15
at String.replace (<anonymous>)
at Hexo.backtickCodeBlock (F:\blog\init\node_modules\hexo\lib\plugins\filter\before_post_render\backtick_code_block.js:15:31)
at Hexo.tryCatcher (F:\blog\init\node_modules\bluebird\js\release\util.js:16:23)
at Hexo.<anonymous> (F:\blog\init\node_modules\bluebird\js\release\method.js:15:34)
at F:\blog\init\node_modules\hexo\lib\extend\filter.js:68:35
at tryCatcher (F:\blog\init\node_modules\bluebird\js\release\util.js:16:23)
at Object.gotValue (F:\blog\init\node_modules\bluebird\js\release\reduce.js:155:18)
at Object.gotAccum (F:\blog\init\node_modules\bluebird\js\release\reduce.js:144:25)
at Object.tryCatcher (F:\blog\init\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (F:\blog\init\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (F:\blog\init\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromiseCtx (F:\blog\init\node_modules\bluebird\js\release\promise.js:606:10)
at Async._drainQueue (F:\blog\init\node_modules\bluebird\js\release\async.js:138:12)
at Async._drainQueues (F:\blog\init\node_modules\bluebird\js\release\async.js:143:10)

解决办法:

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

4.首页文章如何只显示一部分?

这个只要在文章中加上<!--more-->标记 ,该标记以后部分就不在显示了,只有展开全部才显示,这是hexo定义的。

这样每次添加这个标记有点麻烦,也可以自定义添加,不过可能会导致排版错乱,自定义配置链接
https://twiceyuan.com/2014/05/25/hexo%E8%87%AA%E5%8A%A8%E6%B7%BB%E5%8A%A0readmore%E6%A0%87%E8%AE%B0/

5.