hugo项目结构

my-blog/
├── archetypes/         # 内容模板
├── assets/             # 需要 Hugo Pipes 处理的资源 (SCSS, JS)
├── content/            # Markdown 内容
├── layouts/            # 模板布局 (覆盖主题)
├── static/             # 静态文件 (图片, 字体)
├── themes/             # 主题目录
└── hugo.yaml           # 核心配置文件

快速生成并推送到github网页

1.Windows系统

编辑一个deploy.ps1文件(.bat 是 cmd 的脚本,而 .ps1 是 PowerShell 的脚本)实现自动化推送比如:

 1param (
 2    [string]$msg = $(Read-Host "请输入本次提交信息")
 3)
 4
 5# 进入 Hugo 项目根目录
 6cd F:\myblog
 7
 8# 生成 Hugo 网页(包含草稿)
 9hugo -D
10
11# 进入 public/ 目录
12cd public
13
14# 添加所有修改
15git add .
16
17# 提交
18git commit -m "$msg"
19
20# 强制推送到 gh-pages 分支
21git push -f origin gh-pages
22
23# 返回项目根目录
24cd ..
25
26# 输出提示信息
27Write-Host ""
28Write-Host "======================================" -ForegroundColor Yellow
29Write-Host "✅ 网站已成功部署!" -ForegroundColor Green
30Write-Host "🌐 访问地址: https://caoxuan5211.github.io/" -ForegroundColor Cyan
31Write-Host "======================================" -ForegroundColor Yellow

生成文档间链接

1.普通文档链接

目前只用到了相对路径

[关于我](https://caoxuan5211.github.io/blog/kmp/ "悬停指示(标题)")

2.利用html语法多样化链接显示

<a href="https://caoxuan5211.github.io/blog/kmp/" style="color:red;" title = "悬停指示(标题)">关于我</a>

hugo“模板覆盖”规则

Hugo 会先在我们自己的站点根目录 layouts/ 下查找模板文件,如果存在就用它,而不用 themes/PaperMod/layouts/ 的文件(被覆盖了)。

例如:

themes/PaperMod/layouts/partials/head.html  # papermod主题自带
myblog/layouts/partials/head.html       # 我们自己的的覆盖文件,会优先使用

只要你在 myblog/layouts/partials/ 里放同路径的文件,Hugo 就会用你自己的版本。