跳转到内容

主题系统概述

Gridea Pro 的主题系统是其最强大的特性之一,支持 Jinja2 (Pongo2)Go TemplatesEJS 三种模板引擎,让不同技术背景的开发者都能轻松创建主题。

引擎config.json 中的值推荐场景特点
Jinja2 (Pongo2)"jinja2"新主题开发(默认推荐)语法直觉、模板继承优雅、跨语言通用
Go Templates"go"从 Hugo 迁移 / 熟悉 Go与后端语言一致、性能优异
EJS"ejs"旧版主题兼容主要用于向后兼容,新主题不推荐
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.jsontemplates/index.htmltemplates/post.html

config.json 中通过 templateEngine 字段声明引擎:

{
"name": "my-theme",
"version": "1.0.0",
"templateEngine": "jinja2",
"customConfig": []
}

Gridea Pro 构建博客时按以下流程执行:

  1. 加载配置 — 读取 config.json,解析主题元信息和自定义配置
  2. 准备数据 — 组装模板变量(configtheme_configpoststags 等)
  3. 初始化引擎 — 根据 templateEngine 初始化对应模板引擎
  4. 渲染页面 — 依次渲染首页、文章页、归档页、标签页等
  5. 复制资源 — 将 assets/ 内容复制到输出目录(去除 assets/ 前缀)
  6. 输出完成 — 生成完整的静态站点

选择你的引擎,阅读对应的详细指南:

通用参考资料: