feat(route): add Dorohedoro News (#12624)

* feat(route): add Dorohedoro News

* fix maintainer
This commit is contained in:
Ethan Shen 2023-06-07 14:25:02 +08:00 committed by GitHub
parent 4f9262cd88
commit 89e66ea39c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 0 deletions

View File

@ -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
### 免费游戏

View File

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

69
lib/v2/dorohedoro/news.js Normal file
View File

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

View File

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

View File

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