feat(route): add dayanzai (#8950)
* Add(route): add dayanzai * 添加获取全文参数 * Update docs/bbs.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: string literals Co-authored-by: Nite07 <nmy1207@outlook.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
parent
dc78cb88df
commit
f5960cc285
18
docs/blog.md
18
docs/blog.md
|
|
@ -159,6 +159,18 @@ pageClass: routes
|
|||
|
||||
<Route author="kt286" example="/daxiaamu/home" path="/daxiaamu/home"/>
|
||||
|
||||
## 大眼仔旭
|
||||
|
||||
### 分类
|
||||
|
||||
<Route author="nitezs" example="/dayanzai/windows" path="/dayanzai/:category/:fulltext?" :paramsDesc="['分类','是否获取全文,需要获取则传入参数`y`']" radar="1">
|
||||
|
||||
| 微软应用 | 安卓应用 | 教程资源 | 其他资源 |
|
||||
| ------- | ------- | -------- | ----- |
|
||||
| windows | android | tutorial | other |
|
||||
|
||||
</Route>
|
||||
|
||||
## 華康字型故事
|
||||
|
||||
<Route author="tpnonthealps" example="/fontstory" path="/fontstory" />
|
||||
|
|
@ -268,7 +280,11 @@ pageClass: routes
|
|||
### 文章
|
||||
|
||||
<Route author="naixy28" example="/zhubai/via" path="/zhubai/:id" :paramsDesc="['`id` 为竹白主页 url 中的三级域名,如 via.zhubai.love 的 `id` 为 `via`']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
在路由末尾处加上 `?limit=限制获取数目` 来限制获取条目数量,默认值为`20`
|
||||
:::
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate, parseRelativeDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const rootUrl = 'http://www.dayanzai.me/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { category, fulltext } = ctx.params;
|
||||
const currentUrl = rootUrl + category;
|
||||
const response = await got.get(currentUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const lists = $('div.c-box > div > div.c-zx-list > ul > li');
|
||||
const reg = /日期:(.*?(\s\(.*?\))?)\s/;
|
||||
const list = lists
|
||||
.map((index, item) => {
|
||||
item = $(item).find('div');
|
||||
let date = reg.exec(item.find('div.r > p.other').text())[1];
|
||||
if (date.indexOf('周') !== -1 || date.indexOf('月') !== -1) {
|
||||
date = /\((.*?)\)/.exec(date)[1];
|
||||
date = parseDate(date, 'MM-DD');
|
||||
} else if (date.indexOf('年') !== -1) {
|
||||
date = /\((.*?)\)/.exec(date)[1];
|
||||
date = parseDate(date, 'YYYY-MM-DD');
|
||||
} else {
|
||||
date = parseRelativeDate(date);
|
||||
}
|
||||
return {
|
||||
title: item.find('div.r > p.r-top > span > a').text(),
|
||||
pubDate: timezone(date, +8),
|
||||
description: item.find('div.r > p.desc').text(),
|
||||
link: item.find('div.r > p.r-top > span > a').attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
let items;
|
||||
if (fulltext === 'y') {
|
||||
items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got.get(item.link);
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
item.description = content('div.intro-box').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
} else {
|
||||
items = list;
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `大眼仔旭 ${category}`,
|
||||
link: currentUrl,
|
||||
description: `大眼仔旭 ${category} RSS`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/dayanzai/:category/:fulltext?': ['nitezs'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'dayanzai.me': {
|
||||
_name: '大眼仔旭',
|
||||
'.': [
|
||||
{
|
||||
title: '大眼仔旭',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#dayanzai',
|
||||
source: ['/:category', '/:category/*'],
|
||||
target: '/dayanzai/:category',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:category/:fulltext?', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue