借鑒若愚老師的博文,其中第七條全自動(dòng)寫博客非常之有用丛塌。
使用pm2實(shí)現(xiàn)自動(dòng)監(jiān)控文件變動(dòng),自動(dòng)提交
1.在本地安裝pm2(一個(gè)可在后臺(tái)永久打開(kāi)一個(gè)node小程序的 nodejs應(yīng)用,也可以監(jiān)控文件變化),按照代碼如下:
sudo npm install -g pm2
2.在博客的 resource 文件夾下新建 start.js 蔚晨,內(nèi)容如下:
var process = require('child_process');
process.exec(' hexo g -d', function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
}
});
3.在同級(jí)目錄下創(chuàng)建 watch.json ,內(nèi)容如下
{
"apps" : [{
"name" : "blog",
"script" : "./start.js",
"exec_interpreter": "node",
"exec_mode" : "fork_mode",
"watch" : "_posts"
}]
}
4.使用pm2命令實(shí)現(xiàn)監(jiān)控文件變動(dòng)自動(dòng)提交
pm2 start watch.json
以上即可輕松自動(dòng)部署。