feat: add 游资网热点推荐 & 列表 (#5963)
This commit is contained in:
parent
c9fe4b79d8
commit
164990ffe7
42
docs/game.md
42
docs/game.md
|
|
@ -58,6 +58,48 @@ pageClass: routes
|
|||
|
||||
<Route author="nczitzk" example="/fgo/news" path="/fgo/news"/>
|
||||
|
||||
## GameRes 游资网
|
||||
|
||||
### 热点推荐
|
||||
|
||||
<Route author="nczitzk" example="/gameres/hot" path="/gameres/hot"/>
|
||||
|
||||
### 列表
|
||||
|
||||
<Route author="nczitzk" example="/gameres/list/26" path="/gameres/list/:id" :paramsDesc="['列表 id']">
|
||||
|
||||
产业
|
||||
|
||||
| 厂商・专访 | 观察・投资 | 产品 | 政策 | 电子竞技 | 直播 | 区块链 |
|
||||
| ---------- | ---------- | ---- | ---- | -------- | ---- | ------ |
|
||||
| 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 |
|
||||
|
||||
</Route>
|
||||
|
||||
## GNN.tw 游戏新闻
|
||||
|
||||
### GNN.tw 游戏新闻
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
};
|
||||
|
|
@ -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');
|
||||
};
|
||||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue