feat: 添加4Gamers新闻 (#3224)

This commit is contained in:
hoilc 2019-10-10 14:10:25 +08:00 committed by DIYgod
parent 54d5cd9fc4
commit d941d9d8aa
4 changed files with 54 additions and 0 deletions

View File

@ -20,6 +20,16 @@ pageClass: routes
</Route>
## 4Gamers 新闻
### 分类
<Route author="hoilc" example="/4gamers/category/352" path="/4gamers/category/:category" :paramsDesc="['分类 ID, 可从分类 URL 中找到']"/>
### 标签
<Route author="hoilc" example="/4gamers/tag/英雄聯盟" path="/4gamers/tag/:tag" :paramsDesc="['标签名, 可在标签 URL 中找到']"/>
## a9vgNews 游戏新闻
### a9vgNews 游戏新闻

View File

@ -1807,6 +1807,10 @@ router.get('/kzfeed/topic/:id', require('./routes/kzfeed/topic'));
// 腾讯新闻较真查证平台
router.get('/factcheck', require('./routes/tencent/factcheck'));
// 4Gamers
router.get('/4gamers/category/:category', require('./routes/4gamers/category'));
router.get('/4gamers/tag/:tag', require('./routes/4gamers/tag'));
// 大麦网
router.get('/damai/activity/:city/:category/:subcategory/:keyword?', require('./routes/damai/activity'));

View File

@ -0,0 +1,20 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const category = ctx.params.category;
const response = await got.get(`https://www.4gamers.com.tw/site/api/news/by-category/${category}?pageSize=25`);
const list = response.data.data.results;
ctx.state.data = {
title: `4Gamers - ${list[0].category.name}`,
link: `https://www.4gamers.com.tw/news/category/${category}/`,
item: list.map((item) => ({
title: item.title,
author: item.author.nickname,
description: `<img src="${item.smallBannerUrl}" /><p>${item.intro}</p>`,
pubDate: new Date(item.createPublishedAt * 1),
link: item.canonicalUrl,
})),
};
};

20
lib/routes/4gamers/tag.js Normal file
View File

@ -0,0 +1,20 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const tag = ctx.params.tag;
const response = await got.get(`https://www.4gamers.com.tw/site/api/news/by-tag?tag=${encodeURIComponent(tag)}&pageSize=25`);
const list = response.data.data.results;
ctx.state.data = {
title: `4Gamers- #${tag}`,
link: `https://www.4gamers.com.tw/news/tag/${encodeURIComponent(tag)}`,
item: list.map((item) => ({
title: item.title,
author: item.author.nickname,
description: `<img src="${item.smallBannerUrl}" /><p>${item.intro}</p>`,
pubDate: new Date(item.createPublishedAt * 1),
link: item.canonicalUrl,
})),
};
};