feat: Add “Arknights” game official news channel (#2670)

* 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
This commit is contained in:
Astrian Zheng
2019-07-23 01:35:26 +08:00
committed by DIYgod
parent 8100de9847
commit 78327f76e0
3 changed files with 60 additions and 0 deletions

View File

@@ -185,6 +185,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
</Route>
## 明日方舟
### 游戏公告与新闻
<Route author="Astrian" example="/arknights/news" path="/arknights/news"/>
## 小黑盒
### 用户动态

View File

@@ -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;

View File

@@ -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,
};
};