feat: add 剑网3新闻资讯 (#5693)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen
2020-09-25 11:40:17 +01:00
committed by GitHub
co-authored by Henry Wang
parent a6ad432de9
commit 5f963d85e6
3 changed files with 74 additions and 0 deletions
+12
View File
@@ -298,6 +298,18 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<Route author="DIYgod" example="/mhw/news" path="/mhw/news" radar="1"/>
## 剑网 3
### 新闻资讯
<Route author="nczitzk" example="/jx3" path="/jx3/:caty?" :paramsDesc="['分类,见下表,默认为最新']">
| 最新 | 新闻 | 活动 | 公告 |
| ------- | ----- | ---- | -------- |
| allnews | press | hd | announce |
</Route>
## 旅法师营地
### 旅法师营地
+3
View File
@@ -3219,6 +3219,9 @@ router.get('/feixuew/:id?', require('./routes/feixuew/index'));
// 1X
router.get('/1x/:type?/:caty?', require('./routes/1x/index'));
// 剑网3
router.get('/jx3/:caty?', require('./routes/jx3/news'));
// GQ
router.get('/gq/tw/:caty?/:subcaty?', require('./routes/gq/tw/index'));
+59
View File
@@ -0,0 +1,59 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
ctx.params.caty = ctx.params.caty || 'allnews';
let query;
if (ctx.params.caty === 'hd') {
query = 'div.article_list article div h3 a';
} else {
query = 'div.article_list ul li a';
}
const rootUrl = 'https://jx3.xoyo.com';
const currentUrl = `${rootUrl}/${ctx.params.caty}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $(query)
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: url.resolve(rootUrl, item.attr('href')),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('div.detail_con').html();
item.pubDate = new Date(content('p.detail_time').text() + ' GMT+8').toUTCString();
return item;
})
)
);
ctx.state.data = {
title: `${$('ul.allnews_list_ul li.active').text()} - 剑网3`,
link: currentUrl,
item: items,
};
};