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:
Ryan Yuan 2022-02-15 19:13:05 +08:00 committed by GitHub
parent 2949bb4f21
commit b6229bf987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 0 deletions

View File

@ -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>

29
lib/v2/zhubai/index.js Normal file
View File

@ -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,
})),
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:id': ['naixy28'],
};

12
lib/v2/zhubai/radar.js Normal file
View File

@ -0,0 +1,12 @@
module.exports = {
'zhubai.love': {
_name: '竹白',
'.': [
{
title: '文章',
docs: 'https://docs.rsshub.app/blog.html#zhu-bai',
source: ['/'],
},
],
},
};

3
lib/v2/zhubai/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:id', require('./index'));
};