hexo-admin本地部署

使用以下命令即可:

1
npm install hexo-admin --save

hexo s后浏览localhost:4000/admin/,settings设置登录账户和密码,根据提示在_config.yml中配置,如下:

1
2
3
4
5
6
# hexo-admin authentification
admin:
username: qzwjer
password_hash: xxxxxxxxxxxxxxxxxxxxxxx
secret: xxxxxxxxxx
deployCommand: './script/hexo-d.sh'

Deploy需要在_config.yml文件中配置deployCommand,如上最后一行,新建script/hexo-d.sh,内容:

1
2
#!/bin/bash
hexo g && hexo d

Windows10如上配置后,发布仍旧报错,需要更改node_modules/hexo-admin/depoly.js文件的相关函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module.exports = function (command, message, done) {
done = once(done);
//var proc = spawn(command, [message], {detached: true}); //将此行替换为下方
var proc = spawn((process.platform == "win32"?"hexo.cmd":"hexo"), ['d', '-g']);
var stdout = '';
var stderr = '';
proc.stdout.on('data', function(data){stdout += data.toString()})
proc.stderr.on('data', function(data){stderr += data.toString()})
proc.on('error', function(err) {
done(err, {stdout: stdout, stderr: stderr});
});
proc.on('close', function () {
done(null, {stdout: stdout, stderr: stderr});
});
}

如上后即可发布文章也。

新建文章编辑时,右方Publish按钮边的设置按钮,选中有文章的头部信息,开始只有Data,Author,Tags,Catagories,如需添加其它,在_config.yml中配置,例如:

1
2
3
metadata:
top_img: #文章顶部图片
cover: #文章封面