背景
Hugo 博客使用 PaperMod 主题作为 Git submodule 管理。当主题有更新时,需要手动升级。
一键升级脚本
创建脚本 scripts/upgrade-papermod.sh :
#!/usr/bin/env bash
set -euo pipefail
# 颜色输出
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# 检查是否在项目根目录
if [ ! -f "config.yml" ] || [ ! -d "content" ]; then
log_error "请在项目根目录执行此脚本"
exit 1
fi
log_info "开始升级 PaperMod 主题..."
# 显示版本信息
log_info "当前版本:"
git -C themes/PaperMod log -1 --oneline
log_info "待更新版本:"
git -C themes/PaperMod log origin/master -1 --oneline
log_info "待更新提交:"
git -C themes/PaperMod log HEAD..origin/master --oneline
# 更新 submodule
git -C themes/PaperMod fetch origin
git -C themes/PaperMod checkout master
git -C themes/PaperMod merge origin/master
# 验证更新
log_info "新版本: $(git -C themes/PaperMod rev-parse --short HEAD)"
# 测试构建
log_info "测试构建..."
if hugo --gc --minify --cleanDestinationDir --quiet; then
log_info "构建成功!"
else
log_error "构建失败!"
exit 1
fi
log_info "升级完成!"执行升级
# 赋予执行权限
chmod +x scripts/upgrade-papermod.sh
# 执行升级
./scripts/upgrade-papermod.sh提交更改
git add themes/PaperMod
git commit -m "chore: upgrade PaperMod theme"
git push启用 llms.txt(可选)
在 config.yml 中添加:
outputs:
home:
- HTML
- RSS
- JSON
- llms # for LLM indexing
outputFormats:
llms:
mediaType: "text/plain"
baseName: "llms"
isPlainText: true
notAlternative: truellms.txt 是一个帮助 LLM 更好索引博客内容的行业标准格式。