diff --git a/docs/blog.md b/docs/blog.md index d7536cd08a..b28cab4992 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -262,3 +262,13 @@ pageClass: routes ### 分类 + +## 竹白 + +### 文章 + + +::: tip 提示 +在路由末尾处加上 `?limit=限制获取数目` 来限制获取条目数量,默认值为`20` +::: + diff --git a/lib/v2/zhubai/index.js b/lib/v2/zhubai/index.js new file mode 100644 index 0000000000..4827b85c88 --- /dev/null +++ b/lib/v2/zhubai/index.js @@ -0,0 +1,29 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20; + + const response = await got({ + method: 'get', + url: `https://${id}.zhubai.love/api/publications/${id}/posts?publication_id_type=token&limit=${limit}`, + headers: { + Referer: `https://${id}.zhubai.love/`, + }, + }); + const data = response.data.data; + const { name, description } = data[0].publication; + + ctx.state.data = { + title: name, + link: `https://${id}.zhubai.love/`, + description, + item: data.map((item) => ({ + title: item.title, + pubDate: parseDate(item.created_at), + link: `https://${id}.zhubai.love/posts/${item.id}`, + author: name, + })), + }; +}; diff --git a/lib/v2/zhubai/maintainer.js b/lib/v2/zhubai/maintainer.js new file mode 100644 index 0000000000..151d9b468f --- /dev/null +++ b/lib/v2/zhubai/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id': ['naixy28'], +}; diff --git a/lib/v2/zhubai/radar.js b/lib/v2/zhubai/radar.js new file mode 100644 index 0000000000..45d13c4d76 --- /dev/null +++ b/lib/v2/zhubai/radar.js @@ -0,0 +1,12 @@ +module.exports = { + 'zhubai.love': { + _name: '竹白', + '.': [ + { + title: '文章', + docs: 'https://docs.rsshub.app/blog.html#zhu-bai', + source: ['/'], + }, + ], + }, +}; diff --git a/lib/v2/zhubai/router.js b/lib/v2/zhubai/router.js new file mode 100644 index 0000000000..641c23df3a --- /dev/null +++ b/lib/v2/zhubai/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:id', require('./index')); +};