diff --git a/docs/game.md b/docs/game.md index ee8808e4a6..a56555e6cc 100644 --- a/docs/game.md +++ b/docs/game.md @@ -604,6 +604,18 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` | 1 | 2 | 3 | 4 | +## 游戏年轮 + +### 分类 + + + +| PC 游戏 | PS4 游戏 | Switch 游戏 | NS 其他板块 | galgame | VR 游戏 | 3DS 游戏 | psv 游戏 | xbox360 游戏 | ps3 游戏 | 其他掌机 | +| ------- | -------- | ----------- | ----------- | ------- | ------- | -------- | -------- | ------------ | -------- | -------- | +| pcgame | ps4 | sgame | nsaita | ps | bt | 3ds | psv | jiaocheng | ps3yx | zhangji | + + + ## 游戏时光 ### 游戏时光新闻 diff --git a/lib/router.js b/lib/router.js index 89dc4ab420..8cbbe2cf54 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4100,4 +4100,7 @@ router.get('/or/:id?', require('./routes/or')); // 海南大学 router.get('/hainanu/ssszs', require('./routes/hainanu/ssszs')); +// 游戏年轮 +router.get('/bibgame/:category?/:type?', require('./routes/bibgame/category')); + module.exports = router; diff --git a/lib/routes/bibgame/category.js b/lib/routes/bibgame/category.js new file mode 100644 index 0000000000..7840575a56 --- /dev/null +++ b/lib/routes/bibgame/category.js @@ -0,0 +1,57 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const category = ctx.params.category || 'pcgame'; + const type = ctx.params.type || ''; + + const rootUrl = 'https://www.bibgame.com'; + const currentUrl = `${rootUrl}/${category}/${type}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.info_box a') + .slice(0, 15) + .map((_, item) => { + item = $(item); + const link = item.attr('href'); + + return { + title: item.text(), + link: link.indexOf('http') > -1 ? link : `${rootUrl}${link}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + content('#comment').parent().remove(); + + item.description = content('.abstract').html(); + item.pubDate = timezone(new Date(content('.time_box').text().trim()), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};