hexo博客建了好久了,一直以来都有几个痛点:
最近在twitter上受@lencx_启发,发现一套可以全平台多端发布hexo博文的方法,方案如下:
github有手机端,支持ios和android,支持上传图片,网页端也是相当的好用,github action透明发布,不用再关心部署环境。
大家也可以举一反三,使用这种方式,同步发布公众号什么的。
整体github action配置为
name: deploy discussion to hexo blogon: # init workflow # push: # branches: # - source discussion: types: [created, edited]env: # change env here GITHUB_NAME: naosense GITHUB_EMAIL: pingao777@gmail.com GH_TOKEN: ${{ secrets.GH_TOKEN }} ACTION_DEPLOY_KEY: ${{ secrets.HEXO_DEPLOY_SECRET }}jobs: sync: name: Build runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: ref: 'source' - name: Set up Python uses: actions/setup-python@v4 with: python-version: 3.11.4 - name: Get pip cache dir id: pip-cache run: | echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT - name: pip cache uses: actions/cache@v3 with: path: ${{ steps.pip-cache.outputs.dir }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: Install python dependencies run: | python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi if: steps.pip-cache.outputs.cache-hit != 'true' - name: Check discussion if is ready id: check_discussion run: | python deploy.py - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 16.19.0 cache: 'npm' - name: Install hexo and dependencies run: | npm install -g hexo-cli npm install - name: Hexo deploy and Commit md file run: | mkdir -p ~/.ssh/ echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan github.com >> ~/.ssh/known_hosts git config --global user.email "${{ env.GITHUB_EMAIL }}" git config --global user.name "${{ env.GITHUB_NAME }}" git add source/_posts git commit -m 'sync from discussion' \ && git push \ && hexo douban \ && hexo deploy -g \ && echo "Done, congrats!" \ || echo "Oops, something wrong!"
有几点需要注意:
GH_TOKEN
,用来调用github api。这样,你就可以愉快地在地铁里,在被窝里……等任何地方写博客了。