大小写造成的404

之前写文章时发现tag标签还是大写比较顺眼
于是分分钟将md中的标签单词改成大写,重新生成并执行hexo deploy,然而在访问标签时竟然404了
在研究了代码之后,发现这是Git干的好事。

部署原理


关于部署的核心代码在node_modules\hexo-deployer-git\lib\deployer.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
return fs.exists(deployDir).then(function(exist) {
if (exist) return;

log.info('Setting up Git deployment...');
return setup();
}).then(function() {
log.info('Clearing .deploy_git folder...');
return fs.emptyDir(deployDir);
}).then(function() {
log.info('Copying files from public folder...');
return fs.copyDir(publicDir, deployDir);
}).then(function() {
return parseConfig(args);
}).each(function(repo) {
return push(repo);
});

可以看出先检查要部署的文件目录,就是名为.deploy_git的文件夹
没有这目录,那就执行setup函数新建,就是调用

git init
git add -A
git commit -m 'First commit'

如果已经有了那就清空,从public文件夹拷一份最新的过来,解析出远端仓库路径和分支
最后执行push函数将内容上传到Git,就是调用

git add -A
git commit -m 'Site updated: YYYY-MM-DD HH:mm:ss'
git push -u url HEAD:branch --force

原因&解决


明确原理之后看了下.deploy_git中tags文件夹下确实是大写,而远端却是小写,这说明Git并没有检测到大小写的变化。搜索后发现原因是Windows下Git默认是忽略大小写的。
执行git config --global core.ignorecase false开启大小写,再次部署解决