目錄
架構修改如下圖:

參考網站: https://www.criwits.top/page/20220828132827-0gnvmfs
原始workflow yml檔如下:
# chingtsechen.github.io/.github/workflows/gh-pages.yml
name: github pages
on:
  push:
    branches:
      - main  # Set a branch to deploy
jobs:
  deploy:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
        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'  # '0.83.1'
          extended: true  # 有用擴充套件則將 # 移除
      - name: Build
        run: hugo --minify
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public
創建Source Code Repository
設定為Private,外部無法直接訪問

生成公鑰與私鑰
chenqingze@chenqingze-MBP 8. blog % ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""
chenqingze@chenqingze-MBP 8. blog % ll
total 16
drwxr-xr-x@  6 chenqingze  staff   192  9 21 00:37 Kubernetes
drwxr-xr-x@  5 chenqingze  staff   160  9 30 21:37 Python
drwxr-xr-x@ 21 chenqingze  staff   672 10  9 15:25 chingtsechen.github.io
-rw-------   1 chenqingze  staff  3389 10 10 11:02 gh-pages
-rw-r--r--   1 chenqingze  staff   750 10 10 11:02 gh-pages.pub
配置Source Code Repository 私鑰
chenqingze@chenqingze-MBP 8. blog % cat gh-pages


將Source Code 推送進去Repository
由於Source Code Repository是Private的,所以pull code與push code要用帳號和密碼, 現在密碼都改用token的方式,所以要生成一個token

使用帶帳號的方式git clone代碼
# git clone帶帳號
https://chingtsechen@
# @git clone的連結
github.com/chingtsechen/blog-goldfishbrain-fighting.git
# 完整動作
git clone https://[email protected]/chingtsechen/blog-goldfishbrain-fighting.git
# 會要求打密碼,就是使用token
chenqingze@chenqingze-MBP 8. blog % git clone https://[email protected]/chingtsechen/blog-goldfishbrain-fighting.git
Cloning into 'blog-goldfishbrain-fighting'...
Password for 'https://[email protected]':
warning: You appear to have cloned an empty repository.
clone下來會是空目錄,將blog源碼檔案放置進去
chenqingze@chenqingze-MBP blog-goldfishbrain-fighting % ll
total 32
-rw-r--r--@ 1 chenqingze  staff  1066 10 10 11:24 LICENSE
-rw-r--r--@ 1 chenqingze  staff  2874 10 10 11:24 README.md
drwxr-xr-x@ 7 chenqingze  staff   224 10 10 11:24 assets
drwxr-xr-x@ 4 chenqingze  staff   128 10 10 11:24 config
drwxr-xr-x@ 7 chenqingze  staff   224 10 10 11:24 content
-rw-r--r--@ 1 chenqingze  staff   130 10 10 11:25 go.mod
-rw-r--r--@ 1 chenqingze  staff   199 10 10 11:25 go.sum
drwxr-xr-x@ 5 chenqingze  staff   160 10 10 11:25 layouts
drwxr-xr-x@ 3 chenqingze  staff    96 10 10 11:25 resources
drwxr-xr-x@ 9 chenqingze  staff   288 10 10 11:25 static
drwxr-xr-x@ 3 chenqingze  staff    96 10 10 11:25 template
drwxr-xr-x@ 3 chenqingze  staff    96 10 10 11:26 themes
推送至github
chenqingze@chenqingze-MBP blog-goldfishbrain-fighting % git add . -A
chenqingze@chenqingze-MBP blog-goldfishbrain-fighting % git commit -m "first commit"
chenqingze@chenqingze-MBP blog-goldfishbrain-fighting % git push
可以看到,代碼都push上來了

配置靜態頁Repository 公鑰
chenqingze@chenqingze-MBP 8. blog % cat gh-pages.pub

為Source Code Repository創建workflow
Actions → set up a workflow yourself

workflow代碼如下,#處要注意,需依自己需求去修改
# blog-goldfishbrain-fighting/.github/workflows/main.yml
name: GitHub Pages
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repositories
        uses: actions/checkout@v2
        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
        with:
          deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
          external_repository: chingtsechen/chingtsechen.github.io # 要發佈的repository
          publish_branch: main
          publish_dir: ./public # 要發佈的目錄
          cname: blog.goldfishbrain-fighting.com # 如果有修改域名,這裡打上

可以看到佈屬成功

到靜態頁Repository查看是否佈屬成功

確認Settings->Pages,使用Branch和Custom domain是否設定正確

測試發佈文章
推送代碼至blog-goldfisnbrain-fighting後,workflow執行編譯並推送編譯後靜態頁至chingtsechen.github.io中
 可以看到,發佈文章成功,就此,整體hugo架構修改已大功告成了
可以看到,發佈文章成功,就此,整體hugo架構修改已大功告成了
