fix(mock+docs): 友链字段对齐 Gridea Pro 真实运行时#1
Merged
Merged
Conversation
## 问题
skill 的 mock 数据和 Gridea Pro 真实运行时的友链对象结构不一致,导致:
- 主题作者用 `link.name` / `link.url` 写模板 → mock 测试 PASS,**但客户端真实运行时空白**(`bitcron-pro` 的反例:用真实字段 `link.siteName` 反而 mock 测试空白)
- `template-variables.md` 没有 Link 对象字段表,作者只能猜
- 现有主题三种写法、两种是错的、一种是对的但 mock 渲染失败 —— 用户在客户端实测才能暴露
## Gridea Pro 真实运行时(来源代码确认)
- 数据来源:`backend/internal/engine/data_builder.go` 第 232-247 行
把 `domain.Link` 注入到 `customConfig.links`,字段重命名:
- `Name` → `siteName`
- `Url` → `siteLink`
- `Description` / `Avatar` 保持原名
- 渲染暴露:`backend/internal/render/jinja2_renderer.go` 第 231-256 行
把 `customConfig.links` **同时**暴露为顶层 `links` 变量和 `theme_config.links`
→ 主题既可以写 `{% for l in links %}` 也可以写 `{% for l in theme_config.links %}`
## 修复
### 1. `assets/mock-data.json`
友链字段从 `name` / `url` 改为 `siteName` / `siteLink`,对齐真实运行时。
删除 `id` 字段(真实运行时不暴露给模板)。
### 2. `scripts/render_test.py`
`build_context()` 复刻 `jinja2_renderer.buildContext` 行为:
把 mock 友链同时注入到顶层 `links` 和 `theme_config.links`(之前只注入了顶层)。
删除 links.html 分支的特殊处理(base ctx 已包含)。
### 3. `references/template-variables.md`
- 新增「Link 对象」章节,列出 4 个真实字段 + 完整遍历示例 + 易错速查
- 「各页面可用变量表」补充说明 `links` 全局可用
- 文末「易错变量速查」总表加入 `link.name → siteName` 等 4 行
## 验证
- ✅ JSON 合法
- ✅ bitcron-pro 主题 links.html:之前 mock 渲染显示空白,修复后正确输出
「Gridea Pro / 基于 Wails 的桌面静态博客写作客户端」
- ✅ 修改全部为增量性质,不删除任何旧逻辑,不影响其他模板
## 配套关联
- gridea-pro-themes#9:liushen 主题友链页同样字段问题的双兼容修复(已提)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
skill 的 mock 数据和 Gridea Pro 真实运行时的友链对象结构不一致,导致主题作者无法靠 `render_test.py` 暴露真实问题。具体表现:
仓库当前三个 Jinja2 主题(`bitcron-pro` / `memos` / 即将合入的 `liushen`)三种写法,两种是错的——这本身就说明文档和 mock 都不够规范。
Gridea Pro 真实运行时(来源代码确认)
代码证据:
修复内容
1. `assets/mock-data.json`
友链对象字段对齐真实运行时:`name` → `siteName`,`url` → `siteLink`,删除 `id`(真实运行时不暴露)。
2. `scripts/render_test.py`
`build_context()` 复刻 `jinja2_renderer.buildContext` 的双路径行为 —— 把 mock 友链同时注入到顶层 `links` 和 `theme_config.links`(之前只注入了顶层)。删除 links.html 分支的特殊处理(base ctx 已包含)。
3. `references/template-variables.md`
验证
`<div class="link_name">Gridea Pro` + `<div class="link_desc">基于 Wails 的桌面静态博客写作客户端`
配套 PR
Test plan
🤖 Generated with Claude Code