Github Action提供自动化构建,本文重点演示利用其构建并自动发布Hexo博客.

Github 配置

  1. yml配置文件
name: Build and Display

on:
  push:
  	# 配置分支
    branches: [main]
  workflow_dispatch:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Check out
      uses: actions/[email protected]
    - name: set up node
      uses: actions/[email protected]
      with:
        node-version: 14.x
    - name: Install hexo
      run: |
        npm install hexo-cli -g
        npm install hexo --no-optional
    - name: Build
      run: hexo g
    - name: Commit
      run: |
        git config --local user.email "[email protected]"
        git config --local user.name "Lparksi Hexo Bot"
        git add docs
        git commit -m "Commit by Lparksi Hexo Bot" -a
    - name: Push
      uses: ad-m/[email protected]
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.ref }}
      
  1. 开启 Actions 功能
sOa8Df.png

粘入上述代码。

  1. 开启并配置Github Pages服务
sOd9Z8.png
sOaxMt.png

将根目录改为docs

Hexo配置

配置站点配置文件 _config.yml

...
url: https://xxx.github.io
...
public_dir: docs

  • 尤其要把public_dir改为docs

接着便可以在github上编辑Markdown文件自动生成博客了。