快轉到主要內容
  1. 筆記/
  2. 架站筆記/

Hugo 專案更新與部署流程

Web Hugo Git 部署 語法 筆記
目錄
Inner Cover Image

步驟提要
#

  1. 複製原專案資料夾、更名
  2. 移除新專案 舊Git遠端連結
  3. 上傳新專案到 GitHub,建立新 repository
  4. 忽略 /hugo.exe/public//resources
  5. 連結到新的 GitHub repository
    →若忘記忽略→ 4.5. 補忽略+刪除
  6. 驗證
  7. 部屬新專案

1. 複製專案資料夾
#

# 在專案的上層目錄執行
robocopy [原資料夾名] [新資料夾名]  /MIR

完成後會得到:

專案上層目錄
├── [原資料夾] 
└── [新資料夾]

git clone

2. 移除新專案 舊Git遠端連結
#

進入新專案:

cd [新資料夾]

刪掉舊 repo 的 .git:

rmdir /S /Q .git

這樣就不會帶到:

  • 舊 commit
  • 舊 remote
  • 舊 branch
  • 舊 GitHub repo 連結

初始化新的 Git 專案:

git init

建立主分支:

git branch -M main

3. 在 GitHub 上建立新的 repository
#

  • 前往 GitHub 網站
  • 點擊右上角的 “+” → “New repository”
  • Repository name 填入:[新資料夾名]
  • 選擇 Public 或 Private
  • 不要勾選 “Initialize this repository with a README”
  • 點擊 “Create repository”

4. .gitignore 設定忽略
#

從 GitHub Desktop 設定
GitHub Desktop → Repository → Repository settings...

Repository settings in GitHub Desktop

Ignored files 中,輸入/hugo.exe/public//resources

Ignored files in Repository settings

對檔案點選右鍵 → 選單 → Ignored fileIgnored files 中,輸入/hugo.exe/public//resources

Ignored files in Repository settings

5. 連結到新的 GitHub repository
#

# 添加新的遠端連結
git remote add origin https://github.com/[帳號]/[新資料夾名].git

# 推送到新的 repository
git push -u origin main

注意:如果預設分支是 master 而非 main,請將上面的 main 改成 master。可以用 git branch 查看目前的分支名稱。

4.5. 補忽略+刪除
#

若發現上傳到/hugo.exe/public//resources/ 則需 先停止 git追蹤,再刪除雲端檔案

停止追蹤 hugo.exe 和 public/
#

# 1. 從 Git 追蹤中移除(但保留本地檔案)
git rm --cached hugo.exe
git rm -r --cached public/
git rm -r --cached resources/

# 2. 確認 .gitignore 內容正確
# 應該包含:
# hugo.exe
# /public/
# /resources/
# 若不正確 → 執行步驟4. 從GitHub Desktop中設定忽略

# 3. 提交這個「停止追蹤」的變更
git add .gitignore
git commit -m "Stop tracking hugo.exe, public and resource folder"

# 4. 推送到 GitHub
git push

從 GitHub 刪除這些檔案
#

上面的 git push 就已經完成刪除了!因為:

  • git rm --cached = 告訴 Git「不要再追蹤這些檔案」
  • git commit + git push = 把這個「刪除追蹤」的動作同步到 GitHub
  • GitHub 上的 hugo.exe 和 public/ 會被移除

驗證是否成功
#

# 檢查本地狀態
git status
# 應該顯示:working tree clean
# hugo.exe 和 public/ 以及 resources/ 不應該出現在列表中

# 檢查 GitHub
# 去 GitHub repo 頁面看,hugo.exe 和 public/ 以及 resources/ 應該消失了

預期結果
#

  • 本地:hugo.exe 和 public/ 以及 resources/ 資料夾還在,可以正常使用
  • Git:不再追蹤這些檔案
  • GitHub:這些檔案會被刪除
  • 之後:無論怎麼修改這些檔案,都不會被 Git 偵測到

6. 驗證
#

# 確認遠端連結
git remote -v

應該會看到:

origin  https://github.com/[帳號]/[新資料夾名].git (fetch)
origin  https://github.com/[帳號]/[新資料夾名]5.git (push)

完成後,就有兩個獨立的專案了:

  • [原資料夾名] → 連結到舊的 GitHub repo
  • [新資料夾名] → 連結到新的 GitHub repo

7. 部屬新專案
#

到: Cloudflare Dashboard

Workers 和 Pages [+] 建立應用程式

展示 Cloudflare 部署網站操作

Pages

連接 GitHub repo
若無顯示 repo 則需依指示設定 GitHub 應用程式的存取權限

展示 Cloudflare 設定 GitHub 應用程式的存取權限作

展示 Cloudflare 設定 GitHub 應用程式的存取權限作

組件設定
#

Framework 預設

組件命令
hugo
組件輸出目錄
/public
環境變數
變數名稱HUGO_VERSION = 0.1420

可於 cmd 中輸入

hugo version

確認使用的 Hugo 版本