feat: 分离文章slug与URL字段并支持slug模式匹配查询

- 新增 `post_url` 字段存储文章完整URL,`post_slug` 仅存储标识符
- 更新管理后台评论列表、编辑、统计及域名获取接口以使用新字段
- 修改公共评论查询接口,支持slug精确匹配及带`?`、`#`参数的模糊匹配
- 更新前端管理界面,在评论编辑表单中增加"评论地址"(`postUrl`)字段
- 同步更新API文档,明确字段用途及查询参数说明
This commit is contained in:
anghunk
2026-02-09 13:36:25 +08:00
parent b2fd3e72e6
commit cf1e5b5c51
10 changed files with 135 additions and 51 deletions

View File

@@ -16,12 +16,12 @@ GET /api/comments
**查询参数**
| 名称 | 位置 | 类型 | 必填 | 说明 |
| ----------- | ----- | ------- | ---- | -------------------------------------------------------------------------------------------- |
| `post_slug` | query | string | 是 | 使用 `window.location.origin + window`location.pathname`,获取带域名的链接,否则后台无法识别 |
| `page` | query | integer | 否 | 页码,默认 `1` |
| `limit` | query | integer | 否 | 每页数量,默认 `20`,最大 `50` |
| `nested` | query | string | 否 | 是否返回嵌套结构,默认 `'true'` |
| 名称 | 位置 | 类型 | 必填 | 说明 |
| ----------- | ----- | ------- | ---- | ------------------------------------------ |
| `post_slug` | query | string | 是 | 文章 slug与前端 `CWDComments``postSlug` 参数对应 |
| `page` | query | integer | 否 | 页码,默认 `1` |
| `limit` | query | integer | 否 | 每页数量,默认 `20`,最大 `50` |
| `nested` | query | string | 否 | 是否返回嵌套结构,默认 `'true'` |
**成功响应**
@@ -70,6 +70,25 @@ GET /api/comments
}
```
返回字段说明:
| 字段名 | 类型 | 说明 |
| ----------- | ------ | -------------------------- |
| `id` | number | 评论 ID |
| `author` | string | 评论者昵称 |
| `email` | string | 评论者邮箱hash后 |
| `url` | string | null) | 评论者个人主页地址 |
| `contentText` | string | 评论内容(纯文本) |
| `contentHtml` | string | 评论内容(渲染后的 HTML |
| `pubDate` | string | 发布时间ISO 8601 格式) |
| `postSlug` | string | 文章 slug |
| `avatar` | string | 头像 URLGravatar |
| `priority` | number | 置顶权重,数值越大排序越靠前 |
| `likes` | number | 点赞数,默认为 0 |
| `replies` | array | 子评论列表(嵌套结构时) |
| `parentId` | number | null) | 父评论 ID回复时 |
| `replyToAuthor` | string( | null) | 被回复者的昵称(回复时) |
说明:
-`nested=true`(默认)时,接口返回的是"根评论列表",每条根评论包含其 `replies`
@@ -121,7 +140,7 @@ POST /api/comments
```json
{
"post_slug": "https://example.com/blog/hello-world",
"post_slug": "hello-world",
"post_title": "博客标题,可选",
"post_url": "https://example.com/blog/hello-world",
"name": "张三",
@@ -135,16 +154,16 @@ POST /api/comments
字段说明:
| 字段名 | 类型 | 必填 | 说明 |
| ------------ | ------ | ---- | ------------------------------------------------------------------------------------------------------------- |
| `post_slug` | string | 是 | 文章唯一标识符,应与前端组件初始化时的 `postSlug` 值一致,`window.location.origin + window.location.pathname` |
| `post_title` | string | 否 | 文章标题,用于邮件通知内容 |
| `post_url` | string | 否 | 文章 URL用于邮件通知中的跳转链接 |
| `name` | string | 是 | 评论者昵称 |
| `email` | string | 是 | 评论者邮箱,需为合法邮箱格式 |
| `url` | string | 否 | 评论者个人主页或站点地址 |
| `content` | string | 是 | 评论内容,内部会过滤 `<script>...</script>` 片段 |
| `parent_id` | number | 否 | 父评论 ID用于回复功能缺省或 `null` 表示根评论 |
| 字段名 | 类型 | 必填 | 说明 |
| ------------ | ------ | ---- | -------------------------------------------------------------------- |
| `post_slug` | string | 是 | 文章 slug,应与前端组件初始化时的 `postSlug` 值一致,如 `hello-world` |
| `post_title` | string | 否 | 文章标题,用于邮件通知内容 |
| `post_url` | string | 否 | 文章完整 URL用于邮件通知中的跳转链接 |
| `name` | string | 是 | 评论者昵称 |
| `email` | string | | 是 | 评论者邮箱,需为合法邮箱格式 |
| `url` | string | 否 | 评论者个人主页或站点地址 |
| `content` | string | 是 | 评论内容,内部会过滤 `<script>...</script>` 片段 |
| `parent_id` | number | 否 | 父评论 ID用于回复功能缺省或 `null` 表示根评论 |
| `adminToken` | string | 否 | 管理员评论密钥,博主发布评论时需要先通过 `/api/verify-admin` 验证密钥后将密钥传入此字段,评论将直接通过且不受审核设置影响 |
**成功响应**