From 78327f76e02d7203869a335267f7efc8b7a7265f Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Tue, 23 Jul 2019 01:35:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20=E2=80=9CArknights=E2=80=9D=20gam?= =?UTF-8?q?e=20official=20news=20channel=20(#2670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add “Arknights” game official news channel * Update docs for new “Arknights” channel * Fix cache issue with “Arknights” channel * Update document in standard format * Update document in standard format --- docs/game.md | 6 +++++ lib/router.js | 3 +++ lib/routes/arknights/news.js | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 lib/routes/arknights/news.js diff --git a/docs/game.md b/docs/game.md index a4a07771ea..6fc6ca7f69 100644 --- a/docs/game.md +++ b/docs/game.md @@ -185,6 +185,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 +## 明日方舟 + +### 游戏公告与新闻 + + + ## 小黑盒 ### 用户动态 diff --git a/lib/router.js b/lib/router.js index d17418d82a..e09a7a9e8d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1531,4 +1531,7 @@ router.get('/codeceo/:type/:category?', require('./routes/codeceo/category')); // BOF router.get('/bof/home', require('./routes/bof/home')); +// 《明日方舟》游戏 +router.get('/arknights/news', require('./routes/arknights/news')); + module.exports = router; diff --git a/lib/routes/arknights/news.js b/lib/routes/arknights/news.js new file mode 100644 index 0000000000..14b226862f --- /dev/null +++ b/lib/routes/arknights/news.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'https://ak.hypergryph.com/news.html', + }); + + let newslist = response.data; + + const $ = cheerio.load(newslist); + newslist = $('#news > div > div.news-block > ul:first-child > li'); + + newslist = await Promise.all( + newslist + .map(async (index, item) => { + const sth = $(item); + const link = `https://ak.hypergryph.com${sth + .find('a') + .attr('href') + .slice(1)}`; + const description = await ctx.cache.tryGet(link, async () => { + const result = await got.get(link); + const $ = cheerio.load(result.data); + return $('.article-inner').html(); + }); + return { + title: sth + .find('.news-title') + .first() + .text(), + description, + link, + pubDate: new Date( + sth + .find('.news-date-text') + .first() + .text() + ), + }; + }) + .get() + ); + + ctx.state.data = { + title: '《明日方舟》游戏公告与新闻', + link: 'https://ak.hypergryph.com/news.html', + item: newslist, + }; +};