From 2d01ed897b65579eafc85be323ccbae53929beb4 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 3 Mar 2021 05:54:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B8=B8=E8=AE=AF?= =?UTF-8?q?=E7=BD=91=E7=B2=BE=E5=BD=A9=E6=8E=A8=E8=8D=90=20(#7079)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/game.md | 6 ++++ lib/router.js | 3 ++ lib/routes/yxdown/recommend.js | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 lib/routes/yxdown/recommend.js diff --git a/docs/game.md b/docs/game.md index fc4eb0fd3..58391498f 100644 --- a/docs/game.md +++ b/docs/game.md @@ -606,6 +606,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 +## 游讯网 + +### 精彩推荐 + + + ## 游研社 ### 游研社 - 分类文章 diff --git a/lib/router.js b/lib/router.js index c7614f8ee..2751d1258 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/yxdown/recommend.js b/lib/routes/yxdown/recommend.js new file mode 100644 index 000000000..a19bbd29e --- /dev/null +++ b/lib/routes/yxdown/recommend.js @@ -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, + }; +};