feat(route): add 游讯网精彩推荐 (#7079)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen
2021-03-02 16:54:26 -05:00
committed by GitHub
co-authored by NeverBehave
parent 0dce8a0c0a
commit 2d01ed897b
3 changed files with 59 additions and 0 deletions
+6
View File
@@ -606,6 +606,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<Route author="DIYgod" example="/vgtime/keyword/怪物猎人" path="/vgtime/keyword/:keyword" radar="1" rssbud="1"/>
## 游讯网
### 精彩推荐
<Route author="nczitzk" example="/yxdown/recommend" path="/yxdown/recommend"/>
## 游研社
### 游研社 - 分类文章
+3
View File
@@ -3936,6 +3936,9 @@ router.get('/tianyancha/hot', require('./routes/tianyancha/hot'));
// King Arthur
router.get('/kingarthur/:type', require('./routes/kingarthur/index'));
// 游讯网
router.get('/yxdown/recommend', require('./routes/yxdown/recommend'));
// BabeHub
router.get('/babehub/search/:keyword?', require('./routes/babehub/search'));
router.get('/babehub/:category?', require('./routes/babehub/index'));
+50
View File
@@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'http://www.yxdown.com';
const currentUrl = `${rootUrl}/news`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('ul li a b')
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: item.parent().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.pubDate = new Date(content('.intro span').eq(0).text() + ' GMT+8').toUTCString();
content('h1, .intro').remove();
item.description = content('.news').html();
return item;
})
)
);
ctx.state.data = {
title: '精彩推荐 - 游讯网',
link: currentUrl,
item: items,
};
};