基于Github Actions的博客自动化

2023年10月26日 · 342 字 · 1 分钟 · Github

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

hexo clean
hexo generate
hexo algolia
git add .
git commit -m "new psot"
git push -u origin main

全自动脚本

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

#! /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钟,无输入则用时间替代。

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