API 参考 · 内容
内容 API
新闻、公告、帖子、评论、标签、构建索引和作者公开信息. 所有端点只读,只返回已发布内容.
概览
内容正文存 PostgreSQL,公开响应中的 content_html 是服务端清洗后的 HTML. 列表只返回摘要和封面,详情才返回正文. 只返回 status=published 且 published_at <= now() 的内容.
公开详情不增加浏览量
浏览量由站点或后台任务单独统计,读取公开详情不会产生副作用.
内容列表
GET
/v1/content
分页
查询参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
kind | string | 否 | news、announcement 或 post;省略表示全部 |
page | integer | 否 | 从 1 开始,默认 1 |
page_size | integer | 否 | 1-50,默认 10 |
tag | string | 否 | 标签 slug |
q | string | 否 | 标题或摘要关键词 |
sort | string | 否 | published、views 或 updated,默认 published |
请求示例
curl -s "https://api.mcyyt.cn/v1/content?kind=news&page=1&page_size=10&sort=published"
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
data.items | array | 内容列表项 |
data.page | integer | 当前页 |
data.page_size | integer | 每页数量 |
data.total | integer | 总条数 |
data.total_pages | integer | 总页数 |
列表项字段:
| 字段 | 类型 | 说明 |
|---|---|---|
id | string (uuid) | 内容 ID |
slug | string | 唯一 slug |
kind | string | news / announcement / post |
title | string | 标题 |
summary | string | null | 摘要 |
cover_url | string | null | 封面地址 |
cover_alt | string | null | 封面替代文本 |
tags | array | {name, slug, color} |
author_name | string | 作者展示名 |
published_at | string | null | 发布时间 |
updated_at | string | 更新时间 |
is_top | boolean | 是否置顶 |
is_featured | boolean | 是否精选 |
views | integer | 浏览量 |
likes | integer | 点赞数 |
comments_count | integer | 评论数 |
url | string | 官网绝对地址,例如 https://www.mcyyt.cn/news/... |
响应示例
{
"code": 0,
"msg": "ok",
"data": {
"items": [
{
"id": "7f3f0f2e-...",
"slug": "server-update-2026-11",
"kind": "news",
"title": "服务器更新公告",
"summary": "本周维护与更新内容.",
"cover_url": null,
"cover_alt": null,
"tags": [
{"name": "公告", "slug": "announcement", "color": "#ef5777"}
],
"author_name": "YanYuTing",
"published_at": "2026-11-14T08:00:00Z",
"updated_at": "2026-11-14T08:00:00Z",
"is_top": false,
"views": 0,
"likes": 0,
"comments_count": 0,
"url": "https://www.mcyyt.cn/news/server-update-2026-11"
}
],
"page": 1,
"page_size": 10,
"total": 1,
"total_pages": 1
},
"requestId": "req_01..."
}
内容详情
GET
/v1/content/{id_or_slug}
UUID 或 slug
路径参数 id_or_slug 可以是 UUID 或 slug. 详情响应包含列表项的所有字段,并额外包含以下字段:
| 字段 | 类型 | 说明 |
|---|---|---|
content_html | string | 服务端清洗后的正文 HTML |
seo_title | string | null | SEO 标题 |
seo_description | string | null | SEO 描述 |
canonical_url | string | null | 规范地址 |
og_image | string | null | 社交分享图片 |
prev | object | null | {id, title, url} |
next | object | null | {id, title, url} |
legacy_url | string | null | 旧站地址,用于跳转 |
curl -s "https://api.mcyyt.cn/v1/content/server-update-2026-11"
{
"code": 0,
"msg": "ok",
"data": {
"id": "7f3f0f2e-...",
"slug": "server-update-2026-11",
"kind": "news",
"title": "服务器更新公告",
"summary": "本周维护与更新内容.",
"content_html": "<p>...</p>",
"seo_title": "服务器更新公告",
"seo_description": "本周维护与更新内容.",
"canonical_url": "https://www.mcyyt.cn/news/server-update-2026-11",
"og_image": null,
"prev": null,
"next": null,
"legacy_url": null,
"url": "https://www.mcyyt.cn/news/server-update-2026-11"
},
"requestId": "req_01..."
}
未发布、已删除或不存在的内容返回 404. 公开详情不会增加浏览量.
评论
GET
/v1/content/{id}/comments
分页
只返回 status=normal 的评论. 路径参数是内容 UUID.
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
page | integer | 否 | 默认 1 |
page_size | integer | 否 | 默认 20 |
评论字段:
| 字段 | 类型 | 说明 |
|---|---|---|
id | string (uuid) | 评论 ID |
parent_id | string | null | 父评论 ID |
author_name | string | 作者展示名 |
content | string | 评论正文 |
likes | integer | 点赞数 |
created_at | string | 创建时间 |
curl -s "https://api.mcyyt.cn/v1/content/7f3f0f2e-.../comments?page=1&page_size=20"
分页字段与内容列表一致:items、page、page_size、total、total_pages.
标签
GET
/v1/content/tags
无分页
返回全部公开标签. 响应 data.items 中每项包含:
| 字段 | 类型 | 说明 |
|---|---|---|
id | string (uuid) | 标签 ID |
name | string | 标签名 |
slug | string | 标签 slug |
color | string | 十六进制颜色,例如 #ef5777 |
description | string | null | 描述 |
sort_order | integer | 排序值 |
content_count | integer | 该标签下已发布内容数 |
{
"code": 0,
"msg": "ok",
"data": {
"items": [
{"id": "3b2c...", "name": "公告", "slug": "announcement", "color": "#ef5777", "description": null, "sort_order": 0, "content_count": 12}
]
},
"requestId": "req_01..."
}
构建索引
GET
/v1/content/sitemap
构建用
返回全部已发布内容的轻量索引,供官网和搜索构建使用. data 包含 items、total 和 version(内容版本号),可用于构建缓存判断. 每项字段:
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 内容 ID |
slug | string | slug |
kind | string | 内容类型 |
updated_at | string | 更新时间 |
url | string | 官网绝对地址,例如 https://www.mcyyt.cn/news/... |
构建任务可以根据 updated_at 做增量更新,但第一次构建应全量读取.
作者
GET
/v1/authors/{uid}
公开字段
只返回公开字段:uid、nid、username、display_name、avatar_url、bio. 不返回邮箱、密码、封禁信息或账号状态.
{
"code": 0,
"msg": "ok",
"data": {
"uid": "a1b2c3...",
"nid": "a1b2c3...",
"username": "YanYuTing",
"display_name": "YanYuTing",
"avatar_url": null,
"bio": null
},
"requestId": "req_01..."
}
常见错误
| 状态码 | 场景 |
|---|---|
| 422 | page 小于 1、page_size 超过 50、kind 或 sort 不支持 |
| 404 | 内容不存在、未发布、已删除,或评论所属内容不可见 |
| 429 | 超过 IP 限流 |
| 500 | 服务端异常,响应不含堆栈或 SQL |