feat(route): add Dorohedoro News (#12624)
* feat(route): add Dorohedoro News * fix maintainer
This commit is contained in:
parent
4f9262cd88
commit
89e66ea39c
|
|
@ -103,6 +103,12 @@ pageClass: routes
|
|||
|
||||
<Route author="LogicJake" example="/dekudeals/most-wanted" path="/dekudeals/:type" :paramsDesc="['分类名称,可在 URL 中查看']"/>
|
||||
|
||||
## Dorohedoro
|
||||
|
||||
### News
|
||||
|
||||
<Route author="nczitzk" example="/dorohedoro/news" path="/dorohedoro/news" />
|
||||
|
||||
## Epic Games Store
|
||||
|
||||
### 免费游戏
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/news': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 25;
|
||||
|
||||
const rootUrl = 'https://dorohedoro.net';
|
||||
const apiUrl = `${rootUrl}/news/news.xml`;
|
||||
const currentUrl = `${rootUrl}/news/`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('item')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const link = item.find('permalink').text();
|
||||
const isNews = /news_\d+_\d+\.html/.test(link);
|
||||
|
||||
return {
|
||||
title: item.find('title').text(),
|
||||
pubDate: parseDate(item.find('date').text()),
|
||||
link: `${rootUrl}${isNews ? `/news/${link}` : ''}`,
|
||||
isNews,
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (item.isNews) {
|
||||
try {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('#bk_btn').remove();
|
||||
|
||||
item.title = content('.newsTitle').text();
|
||||
item.description = content('article').html();
|
||||
} catch (e) {
|
||||
// no-empty
|
||||
}
|
||||
}
|
||||
|
||||
delete item.isNews;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'アニメ『ドロヘドロ』',
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'dorohedoro.net': {
|
||||
_name: 'Dorohedoro',
|
||||
'.': [
|
||||
{
|
||||
title: 'News',
|
||||
docs: 'https://docs.rsshub.app/game.html#dorohedoro',
|
||||
source: ['/news', '/'],
|
||||
target: '/dorohedoro/news',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/news', require('./news'));
|
||||
};
|
||||
Loading…
Reference in New Issue