diff --git a/docs/game.md b/docs/game.md index 58cb9a274..7dc51fc15 100644 --- a/docs/game.md +++ b/docs/game.md @@ -103,6 +103,12 @@ pageClass: routes +## Dorohedoro + +### News + + + ## Epic Games Store ### 免费游戏 diff --git a/lib/v2/dorohedoro/maintainer.js b/lib/v2/dorohedoro/maintainer.js new file mode 100644 index 000000000..169cca9bc --- /dev/null +++ b/lib/v2/dorohedoro/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['nczitzk'], +}; diff --git a/lib/v2/dorohedoro/news.js b/lib/v2/dorohedoro/news.js new file mode 100644 index 000000000..e285c75e5 --- /dev/null +++ b/lib/v2/dorohedoro/news.js @@ -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, + }; +}; diff --git a/lib/v2/dorohedoro/radar.js b/lib/v2/dorohedoro/radar.js new file mode 100644 index 000000000..a8ebe1ba6 --- /dev/null +++ b/lib/v2/dorohedoro/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/dorohedoro/router.js b/lib/v2/dorohedoro/router.js new file mode 100644 index 000000000..69a5972f6 --- /dev/null +++ b/lib/v2/dorohedoro/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news', require('./news')); +};