模板清单 /templates
返回全部已注册模板及其字段元数据。预览页据此动态生成表单,因此新增模板无需改前端。
GET /templates响应
200 · application/json
jsonc
{
"ok": true,
"templates": [
{
"name": "base",
"label": "基本卡片",
"fields": [
{ "name": "title", "label": "主标题", "type": "text", "defaultValue": "Hello, OG", "maxLength": 120 },
{ "name": "subtitle", "label": "副标题", "type": "text", "defaultValue": "hono + hono-og on Cloudflare Workers", "maxLength": 200 }
],
"size": null // 纯矢量模板无原生尺寸 → width/height 回落框架默认 1200×630
},
{
"name": "rencong-1",
"label": "认怂书(模板1)",
"fields": [ /* … */ ],
"size": { "width": 1055, "height": 1491 } // 底版图片类模板:原生画布尺寸
}
// … 其余模板
]
}字段对象字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
name | string | 查询参数名,也是模板 render 的入参键 |
label | string | 表单标签(人类可读) |
type | string | text | textarea | number | select |
defaultValue | string | number | 缺省值(参数缺失时使用) |
maxLength | number? | text / textarea 的字符上限 |
min / max | number? | number 的取值范围 |
options | string[]? | select 的可选项,第一项即默认值 |
用途
- 构建你自己的调试 / 预览界面:拉一次
/templates即可知道有哪些模板、各自要哪些参数。 - 与服务端校验保持一致:
maxLength/options等约束与服务端parseParams同源。
想看实际字形样本(每种字体一行)而非元数据,调
GET /og?template=font-specimen(见字体清单 /fonts)。