如何用 Hugo 架設個人網站:完整教學
架過很多網站,最後選擇用 Hugo。它太快了——秒級生成、毫無資料庫包袱、主題又多又美。這篇教你從零開始架好一個 Hugo 個人網站。
為什麼選 Hugo?
- ⚡ 極速:Go 語言開發,生成速度以毫秒計
- 📝 純文字:用 Markdown 寫作,版本控制友好
- 🎨 主題豐富:數百個免費主題,PaperMod、LoveIt、Terminal…任你挑
- 🌐 免費托管:GitHub Pages、Netlify、Vercel 統統免費
- 📱 響應式:天生支援手機平板
環境安裝
Windows(用 WSL)
1
2
|
# 在 WSL 終端機執行
wget -qO- https://raw.githubusercontent.com/gohugoio/hugo/master/install.sh | bash
|
macOS
驗證安裝
1
2
|
hugo version
# 看到版本號就代表成功了
|
建立第一個網站
1
2
3
4
5
6
|
# 建立新網站
hugo new site my-site
cd my-site
# 建立第一篇文章
hugo new posts/hello.md
|
安裝主題(以 PaperMod 為例)
1
2
3
4
5
6
|
# 用 git submodule 方式安裝主題
git init
git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/hugo-PaperMod
# 在 hugo.toml 加入
echo 'theme = "hugo-PaperMod"' >> hugo.toml
|
目錄結構
1
2
3
4
5
6
7
|
my-site/
├── content/ # 放你的文章(Markdown)
├── layouts/ # 自訂模板
├── static/ # 靜態檔案(圖片、favicon)
├── themes/ # 主題
├── hugo.toml # 網站設定
└── public/ # 輸出目錄(hugo build 後生成)
|
發布文章
1
2
3
4
5
|
# 本地預覽(開發用)
hugo server -D
# 正式發布
hugo
|
部署到 GitHub Pages
- 在 GitHub 建立
username.github.io repository
- 把
public/ 資料夾的內容 push 上去
- 等個幾秒,你的網站就上線了!
1
2
3
4
5
6
|
cd public
git init
git remote add origin https://github.com/username/username.github.io.git
git add .
git commit -m "first commit"
git push -u origin main
|
結語
Hugo 是那種「用過就回不去」的工具。免費、快速、不用擔心資料庫掛掉,把心力留在寫作上就好。
有問題歡迎留言討論! 🐝
下次再分享如何美化 Hugo 網站的自訂技巧。