feat(content-type): add content_type field, markdown auto-conversion, and API doc updates

- Add content_type column to ul_post via migration
- Install league/commonmark for markdown->HTML conversion
- Add Post model accessors/setters for content_type and content
- Update API Articles controller save/update with content_type support
- Update API docs with content_type parameter and markdown example

Closes content-type-support plan
This commit is contained in:
augushong
2026-04-29 20:46:44 +08:00
parent 0e8944bc7f
commit 6f332467df
5 changed files with 104 additions and 2 deletions

View File

@@ -196,6 +196,7 @@ X-API-Key: {api_key}</div>
"id": 1,
"title": "文章标题",
"content": "文章内容",
"content_type": "html",
"type": "1",
"status": 1,
"source": "api",
@@ -238,6 +239,7 @@ X-API-Key: {api_key}</div>
"title": "文章标题",
"content": "文章内容",
"content_html": "&lt;p&gt;HTML内容&lt;/p&gt;",
"content_type": "html",
"desc": "摘要",
"poster": "/uploads/poster.jpg",
"type": "1",
@@ -268,12 +270,13 @@ X-API-Key: {api_key}</div>
<tr><td>poster</td><td>string</td><td></td><td>封面图 URL</td></tr>
<tr><td>type</td><td>string</td><td></td><td>文章类型,默认 "1"</td></tr>
<tr><td>status</td><td>int</td><td></td><td>状态,默认 0草稿</td></tr>
<tr><td>content_type</td><td>string</td><td></td><td>内容类型: "html"(默认) 或 "markdown"</td></tr>
<tr><td>categorys</td><td>array</td><td></td><td>分类 ID 数组,如 [1, 2]</td></tr>
<tr><td>tags</td><td>array</td><td></td><td>标签 ID 数组,如 [1, 2]</td></tr>
</tbody>
</table>
<h4>请求示例</h4>
<h4>请求示例HTML</h4>
<div class="api-code">curl -X POST \
"https://example.com/index.php/api/articles/save" \
-H "Authorization: Bearer your_api_key" \
@@ -286,6 +289,21 @@ X-API-Key: {api_key}</div>
"tags": [3]
}'</div>
<h4>请求示例Markdown</h4>
<div class="api-code">curl -X POST \
"https://example.com/index.php/api/articles/save" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"title": "Markdown 文章",
"content": "# 标题\n\n段落内容",
"content_type": "markdown",
"type": "1",
"status": 1,
"categorys": [1, 2],
"tags": [3]
}'</div>
<h4>返回示例</h4>
<div class="api-code">{
"code": 0,
@@ -319,6 +337,7 @@ X-API-Key: {api_key}</div>
<tr><td>desc</td><td>string</td><td></td><td>文章摘要</td></tr>
<tr><td>poster</td><td>string</td><td></td><td>封面图 URL</td></tr>
<tr><td>status</td><td>int</td><td></td><td>状态</td></tr>
<tr><td>content_type</td><td>string</td><td></td><td>内容类型: "html"(默认) 或 "markdown"</td></tr>
<tr><td>categorys</td><td>array</td><td></td><td>分类 ID 数组(全量覆盖)</td></tr>
<tr><td>tags</td><td>array</td><td></td><td>标签 ID 数组(全量覆盖)</td></tr>
</tbody>