全自动部署Hexo 到github

有一天把hexo配置好了,但是每次更新后还有手动部署太麻烦。正好有个pm2的工具,完全可以代替我们做这些事。

安装 pm2

1
npm install -g pm2

在博客source目录新建start.json

1
2
3
4
5
6
var process = require('child_process');
process.exec(' hexo g -d', function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
}
});

新建watch.json

1
2
3
4
5
6
7
8
9
{
"apps" : [{
"name" : "blog",
"script" : "./start.js",
"exec_interpreter": "node",
"exec_mode" : "fork_mode",
"watch" : "_posts"
}]
}

使用pm2命令实现监控文件变动自动提交

1
pm2 start watch.json

pm2常用命令

1
2
3
4
pm2 list
pm2 logs
pm2 start watch.json
pm2 show <id|name>

这样就会发现Hexo已经被自动部署到github啦,而且时刻保持最新版

------ 本文结束 ------

版权声明

Medivh's Notes by Medivh is licensed under a Creative Commons BY-NC-ND 4.0 International License.
Medivh创作并维护的Medivh's Notes博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证
本文首发于Medivh 博客( http://www.mknight.cn ),版权所有,侵权必究。