0.1.8 • Published 1 year ago
hexo-restful-api v0.1.8
Hexo Restful Api
Generate restful json in hexo for api or themes that separate front and "back-end".
配置说明
将配置追加到 yml 配置文件中。
allow_origin
:Server 跨域访问配置,默认为 *。black_list
:API 黑名单,其中的 API 不会生成,默认为空。generate_html
:生成作为回退路由的 HTML,配合 Hexo Theme Naive 食用,默认关闭。favicon
:网站图标 URL,默认为空。avatar
:头像 URL,默认为空。bgm
:背景音乐 URL,默认为空。egg
:彩蛋图片 URL,默认为空。github
:代码仓库,默认为空。email
:电子邮箱,默认为空。introductions
:自我介绍列表,默认为空。repos
:Github 仓库列表,默认为空。friends
:友链列表,默认为空。
API 设计
在 Restful API 中博客的唯一标识是 ID,值为 Hexo 的 Permalinks 中的 hash。
对于博客,存在 FullPost、SimplePost 和 TinyPost:
- FullPost 为完整获取博客内容,考虑到传输内容的规模,返回 FullPost 内容的 API 一次调用只返回一篇博客。
- SimplePost 为获取博客除正文外的内容,一般用于目录显示,返回 SimplePost 内容的 API 一次调用可以返回多篇博客,并通过分页的方式防止过长的内容。
- TinyPost 仅获取博客的标题与创建修改时间等基本信息,返回 TinyPost 内容的 API 一次调用可以返回全部博客。
API 列表
返回博客列表时,其顺序为修改时间从近到远。
getInfo
:获取基本配置信息。getAbout
:获取 About 页信息。getPosts
:分页获取博客(SimplePost)。getPostById
:根据 ID 获取博客(FullPost)。getLatestPost
:获取最新的博客(FullPost)。getLatestPosts
:获取最新的 5 篇博客(SimplePost)。getTags
:获取所有 Tag 和每个 Tag 对应的博客(TinyPost)。getPostsByTag
:获取某个 Tag 对应的博客(SimplePost)。getCategories
:获取所有 Category 和每个 Category 对应的博客(TinyPost)。getPostsByCategory
:获取某个 Category 对应的博客(SimplePost)。getDates
:获取存在博客的所有年月及对应的博客(TinyPost)。getPostsByDate
:获取某年某月对应的博客(SimplePost)。getYears
:获取存在博客的所有年份及对应的博客(TinyPost)。getPostsByYear
:获取某年对应的博客(SimplePost)。