From 92ab0efacf82aed63fc32a9a9202d9557a4bb619 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 2 Sep 2020 20:43:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=B0=8F=E5=88=80=E5=A8=B1?= =?UTF-8?q?=E4=B9=90=E7=BD=91=20(#5567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Henry Wang --- docs/new-media.md | 30 +++++++++++++++++++ lib/router.js | 3 ++ lib/routes/x6d/index.js | 65 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 lib/routes/x6d/index.js diff --git a/docs/new-media.md b/docs/new-media.md index f21e8de3e..269d857f8 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1252,6 +1252,36 @@ area 分区选项 +## 小刀娱乐网 + + + +| 技巧分享 | QQ 技巧 | 微信技巧 | 其他教程 | 其他分享 | +| -------- | ------- | -------- | -------- | -------- | +| 31 | 55 | 112 | 33 | 88 | + +| 宅家自学 | 健身养生 | 摄影剪辑 | 长点知识 | 自我提升 | 两性相关 | 编程办公 | 职场关系 | 新媒体运营 | 其他教程 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ---------- | -------- | +| 18 | 98 | 94 | 93 | 99 | 100 | 21 | 22 | 19 | 44 | + +| 活动线报 | 流量话费 | 免费会员 | 实物活动 | 游戏活动 | 红包活动 | 空间域名 | 其他活动 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| 34 | 35 | 91 | 92 | 39 | 38 | 37 | 36 | + +| 值得一看 | 找点乐子 | 热门事件 | 节目推荐 | +| -------- | -------- | -------- | -------- | +| 65 | 50 | 77 | 101 | + +| 值得一听 | 每日一听 | 歌单推荐 | +| -------- | -------- | -------- | +| 71 | 87 | 79 | + +| 资源宝库 | 书籍资料 | 设计资源 | 剪辑资源 | 办公资源 | 壁纸资源 | 编程资源 | +| -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| 106 | 107 | 108 | 109 | 110 | 111 | 113 | + + + ## 新浪专栏 ### 创事记 diff --git a/lib/router.js b/lib/router.js index adffb8a86..b2830b525 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3123,6 +3123,9 @@ router.get('/fjnews/fz/30', require('./routes/fjnews/fznews')); // 九江新闻jjnews router.get('/fjnews/jjnews', require('./routes/fjnews/jjnews')); +// 小刀娱乐网 +router.get('/x6d/:id?', require('./routes/x6d/index')); + // 思维导图社区 router.get('/edrawsoft/mindmap/:classId?/:order?/:sort?/:lang?/:price?/:search?', require('./routes/edrawsoft/mindmap')); diff --git a/lib/routes/x6d/index.js b/lib/routes/x6d/index.js new file mode 100644 index 000000000..19f19f7dd --- /dev/null +++ b/lib/routes/x6d/index.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + let currentUrl; + let query; + + ctx.params.id = ctx.params.id || 'latest'; + + if (ctx.params.id === 'latest') { + currentUrl = 'https://www.x6d.com'; + } else { + currentUrl = `https://www.x6d.com/html/${ctx.params.id}.html`; + } + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + $('i.rj').remove(); + + if (ctx.params.id === 'latest') { + query = $('#newslist ul').eq(0).find('li').not('.addd').find('a'); + } else { + query = $('a.soft-title'); + } + + const list = query + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `https://www.x6d.com${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.article-content').html(); + item.pubDate = new Date(content('time').text() + ' GMT+8').toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `小刀娱乐网 - ${$('title').text().split('-')[0]}`, + link: currentUrl, + item: items, + }; +};