1. 安装必备工具
1.1 安装 Git
去 git-scm.com 下载 Windows 版,一路下一步即可。
验证:
git --version
1.2 安装 Hugo Extended
必须使用 Extended 版本,且版本号为 0.164.0
- 打开 Hugo v0.164.0 下载页
- 下载
hugo_extended_0.164.0_windows-amd64.zip - 解压到
x:\hugo\ - 把
x:\hugo加入系统 PATH:- 按 Win → 搜索「环境变量」→ 编辑系统环境变量
- Path → 新建 →
x:\hugo
验证:
hugo version
# hugo v0.164.0 ... +extended windows/amd64
2. 配置 SSH 密钥
2.1 生成密钥
打开 PowerShell:
ssh-keygen -t ed25519 -C "你的邮箱@example.com"
一路回车(不用设密码),密钥在 ~\.ssh\id_ed25519。
2.2 部署到 GitHub
复制公钥:
type ~\.ssh\id_ed25519.pub
打开浏览器 → github.com/settings/ssh/new :
| 字段 | 填写 |
|---|---|
| Title | Windows 写作机 |
| Key | 粘贴公钥内容 |
点 Add SSH Key。
2.3 验证连接
ssh -T git@github.com
看到 Hi YourSite! 即可。
3. 克隆仓库
cd D:\hugo
git clone --recurse-submodules git@github.com:YourSite/siterepo.git
cd yoursite
--recurse-submodules 会同时拉取主题 themes/xxxx。
4. 本地预览
hugo server -D
浏览器打开 http://localhost:1313,保存即刷新。
| 参数 | 作用 |
|---|---|
-D | 包含草稿 |
| 不加 | 模拟线上效果 |
5. 写新文章
5.1 创建目录
mkdir content\posts\文章别名\images
mkdir content\posts\文章别名\files
5.2 文章模板
新建 content\posts\文章别名\index.md:
+++
title = "文章标题"
description = "摘要"
date = "2026-07-19T00:00:00+08:00"
draft = false
[taxonomies]
categories = ["分享"]
tags = ["标签1"]
[params]
toc = true
image = "cover.png"
+++
<!--more-->
正文……
5.3 目录结构
content\posts\文章别名\
├── index.md
├── cover.png
├── images\
│ ├── a.jpg
│ └── b.jpg
└── files\
6. 发布
git add content/posts/文章别名/
git commit -m "新文章"
git push
CF Pages 自动部署,一分钟后刷新 youresite.com。
一键脚本 (deploy.bat)
@echo off
git add .
git commit -m "更新文章"
git push
echo 已推送
pause
7. 日常速查
| 操作 | 命令 |
|---|---|
| 拉取更新 | git pull |
| 预览 | hugo server -D |
| 升级主题 | git submodule update --remote themes/xxx |
| 查看状态 | git status |