博客搭建好了后每一次更新文章都需要输入以下这些指令将更新内容推送到GitHub,感觉有点繁琐,所以特意写了个shell脚本来一键执行全部指令。

1
2
3
4
5
6
hexo clean
hexo generate
hexo algolia
git add .
git commit -m "new psot"
git push -u origin main

全自动脚本

使用时间作为git commit的内容。

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
#! /bin/bash

echo -e "\033[31;40m--------------------Deploy Begin --------------------"

echo -------------------Step 1 Generate-------------------

cd ../hexo/
hexo clean && hexo generate && hexo algolia

for i in {1..3}; do echo -e "\n" ; done



echo -e "-------------------Step 2 Update-------------------"

git add .
read -p "Input the git commit content: " content
git commit -m "$content"
git push -u origin main

for i in {1..3}; do echo -e "\n" ; done

echo -e "-------------------Deploy End-------------------"

exec /bin/bash

半自动脚本

半自动脚本需要你手动输入git commit的内容,会等待5s钟,无输入则用时间替代。

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
#! /bin/bash

echo -e "\033[31;40m--------------------Deploy Begin --------------------"

echo -------------------Step 1 Generate-------------------

cd ../hexo/
hexo clean && hexo generate && hexo algolia

for i in {1..3}; do echo -e "\n" ; done



echo -e "-------------------Step 2 Update-------------------"

git add .

for i in {1..3}; do echo -e "\n" ; done

time=$(date "+%Y%m%d%H%M%S")
read -t 5 -p "Input the git commit content: " content

if [ -z "$content" ]
then
#echo "you didnt input anything, replace with timestamp !"
git commit -m "$time"
else
git commit -m "$content"
fi

git push -u origin main

for i in {1..3}; do echo -e "\n" ; done

echo -e "-------------------Deploy End-------------------"

exec /bin/bash