hexo一键上传部署脚本的构建

本文最后更新于:2020年2月18日 晚上

  1. windows先右键新建一个文本文档,后缀改为git push hexo.bat;Linux新建一个git push hexo.sh文档;
  2. 注意:编码要是windows默认编码GBK;Linux上是UTF-8;
  3. 然后复制黏贴,话不多说,直接上代码。

Windows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@echo off

cd G:\code\hexo
REM 改为hexo根目录
echo "当前目录是: G:\code\hexo"
REM 改为hexo根目录
echo "正在add... ..."
git add source/
REM 只添加了blog文件目录,需要的可自行添加...
echo;
echo "add complete."
echo;
echo;

echo "正在commit... ..."
set now=%date% %time%
echo %now%
git commit -m "blog update at %now%"
echo;
echo "commit complete."
echo;
echo;

echo "正在将更改提交到远程git服务器... ..."
git push githuborigin hexo && git push giteeorigin hexo && git push codingorigin hexo
echo;
echo "git push complete."
echo;
echo;

echo "正在部署blog... ..."
hexo clean && hexo g && hexo d
echo;
echo "部署 complete."
echo;
echo;

pause

Linux

先提升权限,chmod +x ./git\ push\ hexo.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
cd /home/zs/文档/hexo/closer_laps
# 改为hexo根目录
echo "当前目录是: /home/zs/文档/hexo/closer_laps"

# 改为hexo根目录
echo "正在add... ..."
git add source/
echo;
echo "add complete."
echo;
echo;

echo "正在commit... ..."
now=`date '+%Y-%m-%d %H:%M:%S'`
echo "$now"
git commit -m "blog update at $now"
echo;
echo "commit complete."
echo;
echo;

echo "正在push... ..."
git push githuborigin hexo && git push giteeorigin hexo && git push codingorigin hexo
echo;
echo "git push complete."
echo;
echo;

echo "正在部署blog... ..."
hexo clean && hexo g && hexo d
echo;
echo "部署 complete."
echo;
echo;