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)