From d941d9d8aa4c2cf9e9399e5b708f26b20709eb07 Mon Sep 17 00:00:00 2001 From: hoilc Date: Thu, 10 Oct 2019 14:10:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A04Gamers=E6=96=B0?= =?UTF-8?q?=E9=97=BB=20(#3224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/game.md | 10 ++++++++++ lib/router.js | 4 ++++ lib/routes/4gamers/category.js | 20 ++++++++++++++++++++ lib/routes/4gamers/tag.js | 20 ++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 lib/routes/4gamers/category.js create mode 100644 lib/routes/4gamers/tag.js diff --git a/docs/game.md b/docs/game.md index 22a97e806..50e9e859e 100644 --- a/docs/game.md +++ b/docs/game.md @@ -20,6 +20,16 @@ pageClass: routes +## 4Gamers 新闻 + +### 分类 + + + +### 标签 + + + ## a9vgNews 游戏新闻 ### a9vgNews 游戏新闻 diff --git a/lib/router.js b/lib/router.js index 754aa253b..0992a8628 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/4gamers/category.js b/lib/routes/4gamers/category.js new file mode 100644 index 000000000..c059d235b --- /dev/null +++ b/lib/routes/4gamers/category.js @@ -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: `

${item.intro}

`, + pubDate: new Date(item.createPublishedAt * 1), + link: item.canonicalUrl, + })), + }; +}; diff --git a/lib/routes/4gamers/tag.js b/lib/routes/4gamers/tag.js new file mode 100644 index 000000000..cda07e1e6 --- /dev/null +++ b/lib/routes/4gamers/tag.js @@ -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: `

${item.intro}

`, + pubDate: new Date(item.createPublishedAt * 1), + link: item.canonicalUrl, + })), + }; +};