feat(route): add 竹白blog (#9032)
* Feat: add route for 竹白 * Tweak: change to v2 * Fix: 1. use parseDate 2. update doc 3. support limit query * Fix: 1. ensure limit is number 2. chore doc * Fix: use nullish coalescing * Fix: revert nullish coalescing for not passing DeepScan check * Fix * Chore(doc) Co-authored-by: naixy28 <yuanyang@iftech.io>
This commit is contained in:
parent
2949bb4f21
commit
b6229bf987
10
docs/blog.md
10
docs/blog.md
|
|
@ -262,3 +262,13 @@ pageClass: routes
|
|||
### 分类
|
||||
|
||||
<Route author="XinRoom" example="/ddosi/category/黑客工具" path="/ddosi/category/:category?"/>
|
||||
|
||||
## 竹白
|
||||
|
||||
### 文章
|
||||
|
||||
<Route author="naixy28" example="/zhubai/via" path="/zhubai/:id" :paramsDesc="['`id` 为竹白主页 url 中的三级域名,如 via.zhubai.love 的 `id` 为 `via`']">
|
||||
::: tip 提示
|
||||
在路由末尾处加上 `?limit=限制获取数目` 来限制获取条目数量,默认值为`20`
|
||||
:::
|
||||
</Route>
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:id': ['naixy28'],
|
||||
};
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
module.exports = {
|
||||
'zhubai.love': {
|
||||
_name: '竹白',
|
||||
'.': [
|
||||
{
|
||||
title: '文章',
|
||||
docs: 'https://docs.rsshub.app/blog.html#zhu-bai',
|
||||
source: ['/'],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:id', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue