docs(template-variables): 与 Gridea Pro 真实运行时对齐#3
Merged
Conversation
之前 references/template-variables.md 与引擎实际暴露的模板上下文有 多处出入,导致主题作者用工作量做客户端兜底(fetch /atom.xml 推断 上下篇、自己造 search-index、把分类 fallback 到 tag 等),这次一口气 补齐 + 修错。 【references/template-variables.md】 - Post 对象补字段:id / abstract / description / toc / categories / tagsString / stats / prevPost / nextPost / createdAt / updatedAt / updatedAtFormat / published - **修正旧错**:post.date 实际是 time.Time(不是字符串),展示首选 post.dateFormat;提示用 |date 过滤器换格式 - 新增对象章节:Category / PostStats / SimplePostView(prevPost / nextPost 的元素类型) - Tag 对象补 slug / usedName;Memo 对象补 id / tags / createdAt / createdAtISO / dateFormat - Pagination 补 currentPage / totalPages / totalPosts / hasPrev / hasNext / prevURL / nextURL,保留 prev / next 兼容字段 - 全局变量表补 category / current_tag(别名) / archives / links / commentSetting / site - **新增 category.html 页面**说明:引擎 RenderCategoryPages 自动渲 染每个分类到 /category/<slug>/;同时澄清「没有 categories.html」 - 新增章节《引擎自动生成的输出》:/api/search.json(schema 与 content 脱 HTML 说明)、/feed.xml、/atom.xml、/sitemap.xml、/robots.txt、 /manifest.json,以及客户端 fetch 示例 - **prevPost / nextPost 语义警示**:Gridea Pro 把数组前一项(更新) 赋给 prevPost,与 Hexo / Hugo 习惯相反;移植主题时务必检查方向 【assets/mock-data.json】 - 首篇 mock 文章补:id / abstract / description / toc / categories / stats / prevPost / nextPost / createdAt / updatedAt 等 - 新增 category 全局对象(CategoryView 形式) - tag / current_tag 补 slug 字段 【scripts/render_test.py】 - build_context 补 category.html 模板分支:注入 category 全局 + 按 post.categories 过滤 posts,让带 category.html 的主题(cactus / jasmine / liushen 等)能在 mock 下正常跑通 回归测试:cactus / jasmine / liushen / bitcron-pro 四个仓内主题全部 渲染通过。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
背景
之前在做 cactus / liushen / mango 主题时反复踩到同一类坑:因为
references/template-variables.md与 Gridea Pro 引擎实际暴露的模板上下文有出入,主题作者只好用客户端做兜底(fetch/atom.xml推断上下篇、自己 dump search-index、把分类 fallback 到 tag 等),最后产物又笨又冗余。这次照着
backend/internal/template/types.go、backend/internal/render/jinja2_renderer.go、backend/internal/engine/{engine,page_renderer,search_builder}.go直接对齐一次,省得后面的主题作者继续重复造轮子。Summary
id/abstract/description/toc/categories/tagsString/stats/prevPost/nextPost/createdAt/updatedAt/updatedAtFormat/publishedpost.date是字符串——其实是time.Time(结构体里就是time.Time类型),展示首选post.dateFormat;要换格式就用{{ post.date|date:"layout" }}slug/usedName;Memo 补id/tags/createdAt/createdAtISO/dateFormatcurrentPage/totalPages/totalPosts/hasPrev/hasNext/prevURL/nextURL,保留prev/next别名category/current_tag(别名) /archives/links/commentSetting/site(config别名)category.html页面说明:引擎自动渲染每个分类到/category/<slug>/;同时澄清「没有categories.html」——引擎不暴露全站分类索引页和categories全局数组/api/search.json//feed.xml//atom.xml//sitemap.xml//robots.txt//manifest.json,连带search.json的 schema([{title, link, date, tags, content}],content 已脱 HTML)和客户端 fetch 示例prevPost,与 Hexo / Hugo 习惯相反;从其他生态移植主题时别照搬「上一篇 = 更早」的标签同步更新:
assets/mock-data.json:首篇 mock 文章补齐新字段;新增category全局对象;标签补slugscripts/render_test.py:补category.html模板分支(注入category+ 按post.categories过滤 posts)影响 / 回归测试
直接跑
gridea-pro-themes仓内已合并 + 待合并的主题:无回归。
Test plan
scripts/render_test.py themes/<任一主题>/{{ post.dateFormat }}/{{ post.prevPost.title }}//api/search.json起一个 demo 主题,确认与 Gridea Pro 桌面客户端真实 build 输出一致后续
文档里的语义警示(prevPost = 更新的一篇)建议未来在 Gridea Pro 主程序里做个补救:要么改命名(
olderPost/newerPost),要么至少在主程序文档里加红字提示。这个 PR 不动主程序,只把现状文档化,免得新主题作者继续踩同一个坑。🤖 Generated with Claude Code