diff --git a/docs/game.md b/docs/game.md index f20d3f287..fd2dcbb8c 100644 --- a/docs/game.md +++ b/docs/game.md @@ -855,6 +855,18 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` +## 游戏日报 + +### 分类 + + + +| 资讯 | 访谈 | 服务 | 游理游据 | +| ---- | ------- | ------- | -------- | +| info | talking | service | comments | + + + ## 游戏时光 ### 游戏时光新闻 diff --git a/lib/v2/yxrb/home.js b/lib/v2/yxrb/home.js new file mode 100644 index 000000000..ac40ce1cb --- /dev/null +++ b/lib/v2/yxrb/home.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const baseUrl = 'http://news.yxrb.net'; + +module.exports = async (ctx) => { + const { category = 'info' } = ctx.params; + const link = `${baseUrl}/${category}/`; + const response = await got(link); + const $ = cheerio.load(response.data); + + const list = $('.channel-news .item') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('.title a').attr('title'), + link: `${baseUrl}${item.find('.title a').attr('href')}`, + author: item.find('.author a').text().split('作者 : ')[1], + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = cheerio.load(response.data); + + item.author = item.author ? item.author : $('.author-info .name a').text().split('作者 : ')[1]; + item.pubDate = timezone( + parseDate( + $('.publish-time') + .first() + .contents() + .filter((_, e) => e.nodeType === 3) + .text() + .trim(), + 'YYYY-MM-DD HH:mm:ss' + ), + 8 + ); + item.description = $('article').html(); + item.category = $('.tags a') + .toArray() + .map((item) => $(item).text()); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + description: $('head meta[name=description]').attr('content'), + link, + image: $('.channel-img img').attr('src'), + item: items, + }; +}; diff --git a/lib/v2/yxrb/maintainer.js b/lib/v2/yxrb/maintainer.js new file mode 100644 index 000000000..9644afe02 --- /dev/null +++ b/lib/v2/yxrb/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['TonyRL'], +}; diff --git a/lib/v2/yxrb/radar.js b/lib/v2/yxrb/radar.js new file mode 100644 index 000000000..4009e1da2 --- /dev/null +++ b/lib/v2/yxrb/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'yxrb.net': { + _name: '游戏日报', + news: [ + { + title: '分类', + docs: 'https://docs.rsshub.app/game.html#you-xi-ri-bao', + source: ['/:category', '/'], + target: '/yxrb/:category', + }, + ], + }, +}; diff --git a/lib/v2/yxrb/router.js b/lib/v2/yxrb/router.js new file mode 100644 index 000000000..197778cca --- /dev/null +++ b/lib/v2/yxrb/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:category?', require('./home')); +};