-
Notifications
You must be signed in to change notification settings - Fork 1
API interface CN
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: <config.allowOrigin>
Access-Control-Allow-Credentials: true
数据将以 UTF-8 编码 json 格式返回
你可以从配置文件设置允许跨域访问的域名(设置为 * 为允许所有域名)
-
GET /api/ - 获取当前启用的 API 接口列表
例子:
{ "type": "apiInfo", "data": { "enabled": [ "getInfo", "getPostCount", "getPosts", "getPostsByCategory", "getPostsByCategoryId", "getPostsByTag", "getPostsByTagId", "getPostByPath", "getPostById", "getCategories", "getTags" ] } }
-
GET /api/getInfo/ - 获取当前网站的信息(数据来源与 _config.yml)
例子:
{ "type": "getInfo", "data": { "title": "Hexo中文测试", "subtitle": "", "description": "", "author": "John Doe", "language": "en", "timezone": "", "url": "http://example.com" } }
-
GET /api/getPostCount/ - 获取当前网站的文章数量
例子:
{ "type": "getPostCount", "data": { "count": 10 } }
-
GET /api/getPosts/ - 获取当前网站的文章列表(所有文章)
返回数据
.data.posts: Arraypost:
{ title: String, date: String, description: String, categories: Array, tags: Array, _path: String, _link: String, _id: String }
例子:
{ "type": "getPosts", "data": { "posts": [ { "title": "1", "date": "2022-09-06T01:24:03.000Z", "description": "", "categories": [ { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" }, { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" } ], "tags": [ { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" }, { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" }, { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" } ], "_path": "2022/09/06/1/", "_link": "http://example.com/2022/09/06/1/", "_id": "cl7pldj300000p08detj8etxb" }, { "title": "2", "date": "2022-09-06T01:24:04.000Z", "description": "", "categories": [], "tags": [], "_path": "2022/09/06/2/", "_link": "http://example.com/2022/09/06/2/", "_id": "cl7pldj340001p08d6o7a7z1w" }, { "title": "Hello World", "date": "2022-09-06T01:22:20.002Z", "description": "", "categories": [], "tags": [], "_path": "2022/09/06/hello-world/", "_link": "http://example.com/2022/09/06/hello-world/", "_id": "cl7pldj3h0009p08dcmvx29lk" } ] } }
-
GET /api/getPostsByCategory/:category - 获取当前网站的文章列表(指定分类下的文章)
例子:
{ "type": "getPostsByCategory", "data": [ { "title": "1", "date": "2022-09-06T01:24:03.000Z", "description": "", "categories": [ { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" }, { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" } ], "tags": [ { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" }, { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" }, { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" } ], "_path": "2022/09/06/1/", "_link": "http://example.com/2022/09/06/1/", "_id": "cl7pldj300000p08detj8etxb" } ] }
-
GET /api/getPostsByCategoryId/:categoryId - 获取当前网站的文章列表(指定分类 ID 下的文章)
例子: (与 获取分类下的文章列表 返回的数据相同)
-
GET /api/getPostsByTag/:tag - 获取当前网站的文章列表(指定标签下的文章)
例子:
{ "type": "getPostsByTag", "data": [ { "title": "1", "date": "2022-09-06T01:24:03.000Z", "description": "", "categories": [ { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" }, { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" } ], "tags": [ { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" }, { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" }, { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" } ], "_path": "2022/09/06/1/", "_link": "http://example.com/2022/09/06/1/", "_id": "cl7pldj300000p08detj8etxb" } ] }
-
GET /api/getPostsByTagId/:tagId - 获取当前网站的文章列表(指定标签 ID 下的文章)
例子: (same as 获取标签下的文章列表)
-
GET /api/getPostByPath/:path - 获取指定路径的文章数据
例子: api/getPostByPath/yyyy/mm/dd/hello-world/
{ "type": "getPostByPath", "data": { "title": "Hello World", "date": "2022-09-06T01:22:20.002Z", "description": "", "categories": [], "tags": [], "content": "...html document...", "_id": "cl7pldj3h0009p08dcmvx29lk" } }
-
GET /api/getPostById/:id - 获取指定 ID 的文章数据
例子: (与 获取指定路径的文章数据 返回的数据相同)
-
GET /api/getCategories/ - 获取分类列表
例子:
{ "type": "getCategories", "data": [ { "name": "test1", "_id": "cl7ps65yb0000x88d98gzczh3" }, { "name": "test2", "_id": "cl7ps65yd0003x88d7518aszd" } ] }
-
GET /api/getTags/ - 获取标签列表
例子:
{ "type": "getTags", "data": { "tags": [ { "name": "test_tag1", "_id": "cl7ps65yc0001x88d71rr08su" }, { "name": "test_tag2", "_id": "cl7ps65yc0002x88d2kvegq0o" }, { "name": "test_tag3", "_id": "cl7ps65yd0004x88db7q32te3" } ] } }
-
GET /api/getLatestPost/ - 获取最新的文章.
例子:
{ "type": "getLatestPost", "data": { "title": "test_2_9", "date": "2022-08-22T00:55:51.000Z", "description": "", "categories": [], "tags": [], "content": "...html document...", "_path": "posts/c3f5fdb8.html", "_link": "https://example.com/posts/c3f5fdb8.html", "_id": "cl741rujl00087wnd0tzbhlb8" } }
-
GET /api/getLatest5Posts/ - 获取最新的 5 篇文章.
例子:
{ "type": "getLatest5Posts", "data": [ { "title": "test_2_9", "date": "2022-08-22T00:55:51.000Z", "description": "", "categories": [], "tags": [], "_path": "posts/c3f5fdb8.html", "_link": "https://example.com/posts/c3f5fdb8.html", "_id": "cl741rujl00087wnd0tzbhlb8" }, { "title": "test_2_8", "date": "2022-08-22T00:55:49.000Z", "description": "", "categories": [], "tags": [], "_path": "posts/b4f2cd2e.html", "_link": "https://example.com/posts/b4f2cd2e.html", "_id": "cl741rujj00077wnd443d1lub" }, { "title": "test_2_7", "date": "2022-08-22T00:55:48.000Z", "description": "", "categories": [], "tags": [], "_path": "posts/244dd0bf.html", "_link": "https://example.com/posts/244dd0bf.html", "_id": "cl741ruji00067wndfrpke0ye" }, { "title": "test_2_6来点中文", "date": "2022-08-22T00:55:46.000Z", "description": "", "categories": [], "tags": [], "_path": "posts/534ae029.html", "_link": "https://example.com/posts/534ae029.html", "_id": "cl741ruji00057wndghfnhfxe" }, { "title": "test_2_5", "date": "2022-08-22T00:55:44.000Z", "description": "", "categories": [], "tags": [], "_path": "posts/ca43b193.html", "_link": "https://example.com/posts/ca43b193.html", "_id": "cl741rujh00047wnd2x9o2xye" } ] }