From a589d2feb596d055ca4161b6b89c5f57007e4b78 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 12 Aug 2021 16:57:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B8=B8=E8=BF=85?= =?UTF-8?q?=E7=BD=91=E8=B5=84=E8=AE=AF=20(#7235)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/game.md | 10 +++++++ lib/router.js | 1 + lib/routes/yxdown/news.js | 55 ++++++++++++++++++++++++++++++++++ lib/routes/yxdown/recommend.js | 6 ++-- 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 lib/routes/yxdown/news.js diff --git a/docs/game.md b/docs/game.md index 383336d490..2493407a8f 100644 --- a/docs/game.md +++ b/docs/game.md @@ -640,6 +640,16 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` ## 游讯网 +### 资讯 + + + +| 资讯首页 | 业界动态 | 视频预告 | 新作发布 | 游戏资讯 | 游戏评测 | 网络游戏 | 手机游戏 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| | dongtai | yugao | xinzuo | zixun | pingce | wangluo | shouyou | + + + ### 精彩推荐 diff --git a/lib/router.js b/lib/router.js index 25a2eabf6e..ec6c5d6061 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3982,6 +3982,7 @@ router.get('/news/whxw', require('./routes/news/whxw')); // 游讯网 router.get('/yxdown/recommend', require('./routes/yxdown/recommend')); +router.get('/yxdown/news/:category?', require('./routes/yxdown/news')); // BabeHub router.get('/babehub/search/:keyword?', require('./routes/babehub/search')); diff --git a/lib/routes/yxdown/news.js b/lib/routes/yxdown/news.js new file mode 100644 index 0000000000..1abd41ef4f --- /dev/null +++ b/lib/routes/yxdown/news.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ? `${ctx.params.category}/` : ''; + + const rootUrl = 'http://www.yxdown.com'; + const currentUrl = `${rootUrl}/news/${category}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.div_zixun h2 a') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: `${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); + + content('h1, .intro').remove(); + + item.description = content('.news').html(); + item.pubDate = timezone(parseDate(content('meta[property="og:release_date"]').attr('content')), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.now').text()} - 游讯网`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/routes/yxdown/recommend.js b/lib/routes/yxdown/recommend.js index a19bbd29e7..b111a27f9d 100644 --- a/lib/routes/yxdown/recommend.js +++ b/lib/routes/yxdown/recommend.js @@ -1,5 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const rootUrl = 'http://www.yxdown.com'; @@ -14,6 +16,7 @@ module.exports = async (ctx) => { const list = $('ul li a b') .map((_, item) => { item = $(item); + return { title: item.text(), link: item.parent().attr('href'), @@ -31,11 +34,10 @@ module.exports = async (ctx) => { }); 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(); + item.pubDate = timezone(parseDate(content('meta[property="og:release_date"]').attr('content')), +8); return item; })