在 Hexo 中一键部署 github page 并同步 push 变更文件到指定分支(hexo-deployer-git)
原 deploy
deploy:
- type: git
branch: master
repo: <git repo url>
hexo-deployer-git
分析下该插件是如何只将 public
文件夹内容 push 到分支的
hexo-deployer-git/lib/deployer.js
function setup() {
const userName = args.name || args.user || args.userName || '';
const userEmail = args.email || args.userEmail || '';
// Create a placeholder for the first commit
return fs.writeFile(pathFn.join(deployDir, 'placeholder'), '').then(() => {
return git('init');
}).then(() => {
return userName && git('config', 'user.name', userName);
}).then(() => {
return userEmail && git('config', 'user.email', userEmail);
}).then(() => {
return git('add', '-A');
}).then(() => {
return git('commit', '-m', 'First commit');
});
}
// ......
fs.exists(deployDir).then(exist => {
if (exist) return;
log.info('Setting up Git deployment...');
return setup();
})
该段可以看出每次提交时判断.deploy_git
文件夹是否存在,不存在会创建 .deploy_git
并同时 git init
把该文件夹当作新的提交域,
所以删除了 .git
git add -A
就能 add 全部变更文件了
// ........
fs.exists(deployDir).then(exist => {
if (exist) return;
log.info('Setting up Git deployment...');
return setup();
})
.then(() => {
log.info('Clearing .deploy_git folder...');
return fs.emptyDir(deployDir);
})
.then(() => {
if (args.all) {
log.info('Clearing .deploy_git .git... -ksh');
return fs.rmdirSync(pathFn.join(deployDir, '.git'));
}
})
更改后的 deploy
deploy:
- type: git
branch: master
repo: <git repo url>
- type: git
+ all: true
branch: bolg
repo: <git repo url>
这是修改后的 hexo-deployer-git-ksh
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 kshao-blog-前端知识记录!
评论