增加:腾讯游戏开发者社区 (#918)

- 实现 #704 
- [源页面](http://gameinstitute.qq.com/community/)支持按时间和热度排序,目前只做了按时间输出内容,后续如有需要再加参数控制
- 路由命名和文档写的稍有些拗口,麻烦看下怎么修改比较好(光速逃
This commit is contained in:
凉凉
2018-10-18 17:17:32 +08:00
committed by DIYgod
parent 0449e781dc
commit f0a0c363a7
3 changed files with 77 additions and 0 deletions
+14
View File
@@ -1920,3 +1920,17 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
### 腾讯大家
<route name="首页" author="xyqfer" example="/dajia/index" path="/dajia/index"/>
### 腾讯游戏开发者社区
::: warning 注意
有部分输出全文带有未进行样式处理的代码内容,显示效果不佳,建议跳转原文阅读
:::
<route name="开发者社区" author="xyqfer" example="/gameinstitute/community/hot" path="/gameinstitute/community/:tag?" :paramsDesc="['标签名称,默认为热门']"/>
| 热门 | 策划 | 程序 | 技术前沿 | 音频 | 项目管理 | 游戏运营 | 游戏测试 |
| ---- | ---- | ------- | -------- | ----- | -------- | -------- | -------- |
| hot | plan | program | tech | audio | project | yunying | test |
+3
View File
@@ -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;
+60
View File
@@ -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,
};
};