From 164990ffe747672b9298223554de362e70d82cd2 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 21 Oct 2020 23:24:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=B8=B8=E8=B5=84=E7=BD=91?= =?UTF-8?q?=E7=83=AD=E7=82=B9=E6=8E=A8=E8=8D=90=20&=20=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20(#5963)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/game.md | 42 ++++++++++++++++++++++++++++ lib/router.js | 4 +++ lib/routes/gameres/hot.js | 7 +++++ lib/routes/gameres/list.js | 8 ++++++ lib/routes/gameres/utils.js | 56 +++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 lib/routes/gameres/hot.js create mode 100644 lib/routes/gameres/list.js create mode 100644 lib/routes/gameres/utils.js diff --git a/docs/game.md b/docs/game.md index e44c3f3a8..4079061f9 100644 --- a/docs/game.md +++ b/docs/game.md @@ -58,6 +58,48 @@ pageClass: routes +## GameRes 游资网 + +### 热点推荐 + + + +### 列表 + + + +产业 + +| 厂商・专访 | 观察・投资 | 产品 | 政策 | 电子竞技 | 直播 | 区块链 | +| ---------- | ---------- | ---- | ---- | -------- | ---- | ------ | +| 1 | 11 | 6 | 45 | 14 | 42 | 41 | + +平台 + +| 手游 | 页游・H5 | 端游・PC | 主机 | 虚拟・VR・AR | 云游戏 | +| ---- | -------- | -------- | ---- | ------------ | ------ | +| 5 | 17 | 18 | 21 | 16 | 48 | + +研发 + +| 拆解分析 | 策划 | 程序・引擎 | 美术 | 音乐 | 测试 | +| -------- | ---- | ---------- | ---- | ---- | ---- | +| 24 | 25 | 26 | 27 | 28 | 29 | + +市场 + +| 职场・创业 | 运营・渠道 | 海外 | 数据・报告 | App Store | Steam | +| ---------- | ---------- | ---- | ---------- | --------- | ----- | +| 38 | 34 | 47 | 33 | 46 | 40 | + +其他 + +| 原创 | 硬件・周边 | 八卦 | 活动 | 综合 | +| ---- | ---------- | ---- | ---- | ---- | +| 43 | 44 | 15 | 22 | 39 | + + + ## GNN.tw 游戏新闻 ### GNN.tw 游戏新闻 diff --git a/lib/router.js b/lib/router.js index fe5f0d7d9..a4f597a5e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3376,4 +3376,8 @@ router.get('/stcn/data/:id?', require('./routes/stcn/data')); // dev.to router.get('/dev.to/top/:period', require('./routes/dev.to/top')); +// GameRes 游资网 +router.get('/gameres/hot', require('./routes/gameres/hot')); +router.get('/gameres/list/:id', require('./routes/gameres/list')); + module.exports = router; diff --git a/lib/routes/gameres/hot.js b/lib/routes/gameres/hot.js new file mode 100644 index 000000000..908d837e7 --- /dev/null +++ b/lib/routes/gameres/hot.js @@ -0,0 +1,7 @@ +const utils = require('./utils'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.gameres.com'; + + ctx.state.data = await utils(ctx, rootUrl, '.hot-item h3'); +}; diff --git a/lib/routes/gameres/list.js b/lib/routes/gameres/list.js new file mode 100644 index 000000000..8ef97ee4f --- /dev/null +++ b/lib/routes/gameres/list.js @@ -0,0 +1,8 @@ +const utils = require('./utils'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.gameres.com'; + const currentUrl = `${rootUrl}/list/${ctx.params.id}`; + + ctx.state.data = await utils(ctx, currentUrl, '.feed-item-right a h3'); +}; diff --git a/lib/routes/gameres/utils.js b/lib/routes/gameres/utils.js new file mode 100644 index 000000000..178fb5640 --- /dev/null +++ b/lib/routes/gameres/utils.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx, currentUrl, query) => { + const rootUrl = `https://www.gameres.com`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $(query) + .slice(0, 20) + .map((_, item) => { + item = $(item); + item = item.parent().get(0).tagName === 'a' ? item.parent() : item.children(); + + return { + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .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); + + const description = content('#maincontent'); + const info = description.prev().text().trim().split('\n'); + info.pop(); + const pubDate = info.pop(); + + item.description = description.html(); + item.title = content('.article-title').text(); + item.pubDate = new Date(pubDate).toUTCString(); + item.author = info.join(' ').replace(/作者:/, '').replace(/原创/, ''); + + return item; + }) + ) + ); + + return { + title: $('title').text(), + link: rootUrl, + item: items, + }; +};