背景

这个博客从 2013 年底开始,使用 Jekyll 托管在 GitHub Pages 上,经历了几次主题变更。最近一次使用的是 jekyll-theme-chirpy 7.1.1。

积累了 55 篇文章后,决定重新审视技术栈选型,期望找到一个简单、优雅、有技术范的方案。

2026 年静态博客生态

在选型之前,整理了当前主流的静态站点生成器(SSG)对比:

SSG语言构建速度特点
JekyllRuby中等GitHub Pages 原生支持,生态最成熟
HugoGo极快 (<1ms/页)单二进制,零依赖
AstroJS/TS默认零 JS 输出,Island Architecture
11tyJS灵活,多模板引擎
ZolaRust极快单二进制,内置 Sass/语法高亮

为什么选 Hugo + PaperMod

经过评估,最终选择 Hugo + PaperMod:

  1. 构建速度 — 54 篇文章构建时间 <100ms,Jekyll 需要数秒
  2. PaperMod 主题 — 极简优雅,专注内容,暗色模式完美
  3. 零 Ruby 依赖hugo 单个二进制文件,装完即用
  4. 多语言原生支持 — Hugo 内置 i18n 机制,对中英双语友好
  5. 活跃维护 — PaperMod 社区活跃,2026 年仍在持续更新

迁移过程

1. 项目结构变化

1
2
3
4
5
6
7
8
# Jekyll 结构                    # Hugo 结构
├── _config.yml                  ├── hugo.yaml
├── _posts/                      ├── content/posts/
├── _data/                       ├── static/
├── _plugins/                    ├── themes/PaperMod/
├── _tabs/                       ├── archetypes/
├── Gemfile                      └── layouts/
└── assets/

2. Front Matter 标准化

Jekyll 时期 front matter 格式不统一,迁移时统一为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
---
title: "文章标题"
date: 2026-06-26
description: "简短描述"
author: "haoxiqiang"
tags: ["tag1", "tag2"]
categories: ["Category"]
ShowToc: true
TocOpen: false
---

3. 多语言配置

Hugo 的多语言支持通过文件名后缀区分,非常直观:

1
2
3
content/posts/
├── my-post.md        # 中文(默认语言)
└── my-post.en.md     # English

hugo.yaml 中设置 defaultContentLanguage: zh,英文版本通过 /en/ 前缀访问。

4. GitHub Actions 部署

利用 peaceiris/actions-hugo 和 GitHub 官方的 Pages 部署 action:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
name: Deploy Hugo site to Pages
on:
  push:
    branches: ["master"]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
          fetch-depth: 0
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: 'latest'
          extended: true
      - name: Build
        run: hugo --minify
      - uses: actions/upload-pages-artifact@v3
        with:
          path: ./public
  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - uses: actions/deploy-pages@v4

PaperMod 特性

选择 PaperMod 后获得的开箱即用功能:

  • 深色/浅色模式自动切换
  • 站内搜索(基于 Fuse.js)
  • 代码块一键复制
  • 阅读时间估计
  • 文章目录(TOC)
  • 面包屑导航
  • RSS 订阅
  • SEO 优化(Open Graph、Twitter Cards)
  • 响应式设计
  • 归档页面
  • 多语言支持

GitHub Pages 2026 最佳实践

总结一些当前 GitHub Pages 的使用建议:

部署方式

推荐使用 GitHub Actions,不再使用旧的分支部署模式。Actions 方式的优势:

  • 不限于 Jekyll,可使用任何 SSG
  • 构建环境完全可控
  • 始终使用最新版本的工具

性能优化

  • 启用 minify 压缩输出
  • 利用 CDN(GitHub Pages 自带 Fastly CDN)
  • 图片使用 WebP 格式
  • 启用 PWA 缓存支持离线访问

自定义域名

  1. 仓库根目录放置 CNAME 文件
  2. DNS 配置 CNAME 指向 <username>.github.io
  3. GitHub 自动签发 HTTPS 证书

内容管理

  • Markdown 写作,git push 即部署
  • 使用 archetypes 模板快速创建新文章
  • 利用 draft: true 管理草稿

迁移总结

维度之前(Jekyll)之后(Hugo)
构建时间~5s<100ms
依赖安装Ruby + Bundler单个 binary
主题Chirpy 7.1.1PaperMod
多语言不支持原生支持
搜索Fuse.js 全文搜索
文章数5554(去除 1 个重复)

迁移工作量约半天,主要花在统一 front matter 格式上。结果很满意——构建速度从秒级变成毫秒级,主题简洁优雅,多语言也准备就绪。

参考资源