From 1f74080aca0ec23411c1595adaba958b990ff0cd Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 7 Sep 2020 18:18:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E9=A3=9E=E9=9B=AA=E5=A8=B1?= =?UTF-8?q?=E4=B9=90=E7=BD=91=20(#5621)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Henry Wang --- docs/new-media.md | 10 ++++++ lib/router.js | 3 ++ lib/routes/feixuew/index.js | 64 +++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 lib/routes/feixuew/index.js diff --git a/docs/new-media.md b/docs/new-media.md index a3df5871e..dc3d89979 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -578,6 +578,16 @@ area 分区选项 +## 飞雪娱乐网 + + + +| 实用软件 | 网站源码 | 技术教程 | 游戏助手 | 游戏资源 | 值得一看 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| rj | wzym | jsjc | yx | yxzy | zdyk | + + + ## 凤凰网 ### 大风号 diff --git a/lib/router.js b/lib/router.js index 6028e96b2..6f4348f63 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3188,6 +3188,9 @@ router.get('/chuhaibiji', require('./routes/chuhaibiji/index')); // 建宁闲谈 router.get('/blogs/jianning', require('./routes/blogs/jianning')); +// 飞雪娱乐网 +router.get('/feixuew/:id?', require('./routes/feixuew/index')); + // 1X router.get('/1x/:type?/:caty?', require('./routes/1x/index')); diff --git a/lib/routes/feixuew/index.js b/lib/routes/feixuew/index.js new file mode 100644 index 000000000..c7426fcca --- /dev/null +++ b/lib/routes/feixuew/index.js @@ -0,0 +1,64 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + let currentUrl; + let query; + + const rootUrl = 'https://www.feixuew.com'; + + ctx.params.id = ctx.params.id || 'latest'; + + if (ctx.params.id === 'latest') { + currentUrl = rootUrl; + } else { + currentUrl = `${rootUrl}/sort/${ctx.params.id}`; + } + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + if (ctx.params.id === 'latest') { + query = $('ul.ul-new li a').slice(4, 10); + } else { + query = $('a.sjwu').slice(0, 10); + } + + const list = query + .map((_, item) => { + item = $(item); + return { + title: item.attr('title'), + link: ctx.params.id === 'latest' ? `https:${item.attr('href')}` : `${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.info-con').html(); + item.pubDate = new Date(content('p.f-sgray span').eq(1).text().replace('发布时间:', '') + ' GMT+8').toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `飞雪娱乐网 - ${$('title').text().split('-')[0]}`, + link: currentUrl, + item: items, + }; +};