Static sites like mine can easily use Github Pages and Cloudflare to deploy and speed up. However, it's annoying to generate, publish and purge cache by typing every command manually. So, we can use a script to automate this process.
The script should be like this: (Take Hugo for example, Hexo and others should be similar.)
cd /path/to/your/blog
mv public/.git .
rm -rf public
echo "$ hugo"
hugo
mv .git public
cd public
echo "$ git add ."
git add .
echo "$ git commit --allow-empty-message -m ''"
git commit --allow-empty-message -m ''
echo "$ git push origin master"
git push origin master
echo "Press any key to purge Cloudflare cache..."
read -s -n 1
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ID/purge_cache" -H "Content-Type:application/json" -H "Authorization: Bearer $TOKEN" --data '{"purge_everything":true}'
echo
is used to split output, so that you can know its origin. Besides, purging cache by using Cloudflare API needs manual action, since after pushing new contents to Github, it takes time to take effect.
Here is a better version.
cd /path/to/your/blog
mv public/.git .
rm -rf public
echo -e "\033[34mStart building the site.\033[0m"
hugo
mv .git public
cd public
echo -e "\033[34mStart publishing the site.\033[0m"
git add .
git commit --allow-empty-message -m ''
git push origin master
echo -e "\033[34mWait for publishing to take effect.\033[0m"
sleep 30
echo -e "\033[34mStart purging Cloudflare cache.\033[0m"
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ID/purge_cache" -H "Content-Type:application/json" -H "Authorization: Bearer $TOKEN" --data '{"purge_everything":true}'
echo -e "\033[34mWait for purging to take effect.\033[0m"
sleep 10
echo -e "\033[34mUpdate finishes.\033[0m"