Hexo自帶deploy模塊,網上也有不少大神分享各類各樣的CI/CD方案,我沒有想過寫Blog須要這麼複雜,並且Hexo已經很穩定了。我由於開始學習使用MacBook,因此逼着本身把以前用在Windows上的腳本用Python從新寫了下,很簡陋但也很好用,相信你們能夠寫出更加通用和優美的代碼。css
使用Powershell和Python自動化更新和推送Hexo靜態Blog
2018年07月31日 - 初稿python
閱讀原文 - https://wsgzao.github.io/post...git
./deploy_hexo.ps1
# hexo g cd .\hexo hexo clean hexo g # del old files cd ..\wsgzao.github.io Remove-Item about,archives,categories,css,fancybox,font,img,index,js,page,post -recurse -force # deploy github Copy-Item ..\hexo\public\* .\ -recurse -force git add * git commit -m "mod" git push cd ..
python3 deploy_hexo.py
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)