建库,设key#

  • 公共仓库:username.github.io
  • 私有仓库:blog
  • github账户设置:
    • Setting - Developer setting - Personal access tokens
    • 创建一个 Token,选repo和workflow权限(※只能看一次,记得复制)
  • 私有仓库设置:
    • Settings - Secrets - Actions添加PERSONAL_TOKEN

具体设置#

  • 创建blog/.github/workflows/build.yml
name: github pages

on:
  push:
    branches:
      - main  # Set a branch to deploy
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: github.ref == 'refs/heads/main'
        with:
          personal_token: ${{ secrets.PERSONAL_TOKEN }}
          external_repository: szkm330/szkm330.github.io
          publish_branch: main
          publish_dir: ./public