前言
Hexo自带deploy模块,网上也有很多大神分享各种各样的CI/CD方案,我没有想过写Blog需要这么复杂,而且Hexo已经很稳定了。我因为开始学习使用MacBook,所以逼着自己把之前用在Windows上的脚本用Python重新写了下,很简陋但也很好用,相信大家可以写出更加通用和优美的代码。
使用Powershell和Python自动化更新和推送Hexo静态Blog
更新历史
2018年07月31日 - 初稿
阅读原文 - https://wsgzao.github.io/post/hexo-deploy/
Windows
./deploy_hexo.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
cd .\hexo hexo clean hexo g
cd ..\wsgzao.github.io Remove-Item about,archives,categories,css,fancybox,font,img,index,js,page,post -recurse -force
Copy-Item ..\hexo\public\* .\ -recurse -force git add * git commit -m "mod" git push
cd ..
|
MacBook
python3 deploy_hexo.py
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
| import os import sys import subprocess
hexo = os.path.join(os.getcwd(), "hexo") wsgzao = os.path.join(os.getcwd(), "wsgzao.github.io")
home = os.getcwd() print ("current directory %s" % home)
os.chdir(hexo) retval = os.getcwd() print ("chdir to hexo %s" % retval)
subprocess.call(['hexo clean'], shell=True)
subprocess.call(['hexo g'], shell=True)
os.chdir(wsgzao) retval = os.getcwd() print ("chdir to wsgzao %s" % retval)
subprocess.call(['rm -rf about archives categories css fancybox font img index js page post'], shell=True)
subprocess.call(['cp -rf ../hexo/public/* ./'], shell=True)
subprocess.call(['git add *'], shell=True) subprocess.call(['git commit -m "mod"'], shell=True) subprocess.call(['git push'], shell=True)
|