diff --git a/docs/README.md b/docs/README.md index c40198dd0..d0e4e5012 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1920,3 +1920,17 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 ### 腾讯大家 + +### 腾讯游戏开发者社区 + +::: warning 注意 + +有部分输出全文带有未进行样式处理的代码内容,显示效果不佳,建议跳转原文阅读 + +::: + + + +| 热门 | 策划 | 程序 | 技术前沿 | 音频 | 项目管理 | 游戏运营 | 游戏测试 | +| ---- | ---- | ------- | -------- | ----- | -------- | -------- | -------- | +| hot | plan | program | tech | audio | project | yunying | test | diff --git a/router.js b/router.js index 8130288e5..279bbbfb5 100644 --- a/router.js +++ b/router.js @@ -665,4 +665,7 @@ router.get('/dajia/index', require('./routes/dajia/')); // 甩甩尾巴 router.get('/dgtle/trade/:typeId?', require('./routes/dgtle/trade')); +// 腾讯游戏开发者社区 +router.get('/gameinstitute/community/:tag?', require('./routes/gameinstitute/community')); + module.exports = router; diff --git a/routes/gameinstitute/community.js b/routes/gameinstitute/community.js new file mode 100644 index 000000000..69452f0cd --- /dev/null +++ b/routes/gameinstitute/community.js @@ -0,0 +1,60 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { tag = 'hot' } = ctx.params; + + const listRes = await axios({ + method: 'get', + url: `http://gameinstitute.qq.com/community/${tag}/new?p=1&ps=20&ob=new&cid=0&tag=${tag}`, + headers: { + 'X-Requested-With': 'XMLHttpRequest', + }, + }); + + const storyList = listRes.data.archives; + const resultItem = await Promise.all( + storyList.map(async (story) => { + const url = `http://gameinstitute.qq.com/article/detail/${story.id}`; + const item = { + title: story.title, + description: '', + link: url, + author: story.user_name, + pubDate: new Date(story.publish_time).toUTCString(), + }; + const key = `gameinstitute-community: ${url}`; + const value = await ctx.cache.get(key); + + if (value) { + item.description = value; + } else { + const storyDetail = await axios({ + method: 'get', + url: url, + }); + const $ = cheerio.load(storyDetail.data); + $('.art-cont img').each(function(_, item) { + $(item).attr('referrerpolicy', 'no-referrer'); + }); + + // 处理图片左边被截断问题 + $('.art-cont .image-package').each(function(_, item) { + $(item).css('margin', '0'); + }); + + item.description = $('.art-cont').html(); + ctx.cache.set(key, item.description, 24 * 60 * 60); + } + + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: '游戏开发者社区-腾讯游戏学院', + description: '腾讯游戏学院是专门为游戏行业从业者服务的游戏开发者社区,这里有关于游戏开发相关的文章教程、游戏策划、美术作品、还有新鲜的前沿科技资讯。', + link: `http://gameinstitute.qq.com/community/${tag}`, + item: resultItem, + }; +};