主题系统概述
This content is not available in your language yet.
Gridea Pro 的主题系统是其最强大的特性之一,支持 Jinja2 (Pongo2)、Go Templates 和 EJS 三种模板引擎,让不同技术背景的开发者都能轻松创建主题。
| 引擎 | config.json 中的值 | 推荐场景 | 特点 |
|---|---|---|---|
| Jinja2 (Pongo2) | "jinja2" | 新主题开发(默认推荐) | 语法直觉、模板继承优雅、跨语言通用 |
| Go Templates | "go" | 从 Hugo 迁移 / 熟悉 Go | 与后端语言一致、性能优异 |
| EJS | "ejs" | 旧版主题兼容 | 主要用于向后兼容,新主题不推荐 |
主题目录结构
Section titled “主题目录结构”themes/my-theme/├── config.json # 主题配置声明(必需)├── templates/ # 模板文件(必需)│ ├── base.html # 基础布局(强烈推荐)│ ├── index.html # 首页(必需)│ ├── post.html # 文章详情页(必需)│ ├── archives.html # 归档页│ ├── tag.html # 单个标签页│ ├── tags.html # 标签汇总页│ ├── blog.html # 博客列表页(分页)│ ├── 404.html # 错误页│ └── partials/ # 局部模板├── assets/ # 静态资源│ ├── styles/ # CSS / LESS│ └── media/images/ # 图片└── screenshot.png # 主题预览图最小可用主题只需三个文件:config.json、templates/index.html、templates/post.html。
在 config.json 中通过 templateEngine 字段声明引擎:
{ "name": "my-theme", "version": "1.0.0", "templateEngine": "jinja2", "customConfig": []}渲染生命周期
Section titled “渲染生命周期”Gridea Pro 构建博客时按以下流程执行:
- 加载配置 — 读取
config.json,解析主题元信息和自定义配置 - 准备数据 — 组装模板变量(
config、theme_config、posts、tags等) - 初始化引擎 — 根据
templateEngine初始化对应模板引擎 - 渲染页面 — 依次渲染首页、文章页、归档页、标签页等
- 复制资源 — 将
assets/内容复制到输出目录(去除assets/前缀) - 输出完成 — 生成完整的静态站点
选择你的引擎,阅读对应的详细指南:
- Jinja2 (Pongo2) 指南 — 推荐首选
- Go Templates 指南 — 适合 Go 开发者
- EJS 指南 — 旧版兼容
通用参考资料:
- 模板变量参考 — 所有可用变量一览
- 主题配置 Schema — config.json 完整规范