From 4c5280f91ebd39eda6b0243566ba1b4615bc7edb Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 23 Jan 2023 21:16:27 +0200 Subject: [PATCH] fix(route): x6d (#11676) --- docs/new-media.md | 4 ++- lib/router.js | 2 +- lib/routes/x6d/index.js | 64 ---------------------------------------- lib/v2/x6d/index.js | 59 ++++++++++++++++++++++++++++++++++++ lib/v2/x6d/maintainer.js | 3 ++ lib/v2/x6d/radar.js | 13 ++++++++ lib/v2/x6d/router.js | 3 ++ 7 files changed, 82 insertions(+), 66 deletions(-) delete mode 100644 lib/routes/x6d/index.js create mode 100644 lib/v2/x6d/index.js create mode 100644 lib/v2/x6d/maintainer.js create mode 100644 lib/v2/x6d/radar.js create mode 100644 lib/v2/x6d/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 835029e16e..63101c3b6d 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -4189,7 +4189,9 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ ## 小刀娱乐网 - +### 分类 + + | 技巧分享 | QQ 技巧 | 微信技巧 | 其他教程 | 其他分享 | | ---- | ----- | ---- | ---- | ---- | diff --git a/lib/router.js b/lib/router.js index 55e8ec8f7d..224f12925e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3113,7 +3113,7 @@ router.get('/kongfz/shop/:id/:cat?', lazyloadRouteHandler('./routes/kongfz/shop' router.get('/xmind/mindmap/:lang?', lazyloadRouteHandler('./routes/xmind/mindmap')); // 小刀娱乐网 -router.get('/x6d/:id?', lazyloadRouteHandler('./routes/x6d/index')); +// router.get('/x6d/:id?', lazyloadRouteHandler('./routes/x6d/index')); // 思维导图社区 router.get('/edrawsoft/mindmap/:classId?/:order?/:sort?/:lang?/:price?/:search?', lazyloadRouteHandler('./routes/edrawsoft/mindmap')); diff --git a/lib/routes/x6d/index.js b/lib/routes/x6d/index.js deleted file mode 100644 index 3854d86ef8..0000000000 --- a/lib/routes/x6d/index.js +++ /dev/null @@ -1,64 +0,0 @@ -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((item) => - 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, - }; -}; diff --git a/lib/v2/x6d/index.js b/lib/v2/x6d/index.js new file mode 100644 index 0000000000..482d266449 --- /dev/null +++ b/lib/v2/x6d/index.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const baseUrl = 'https://xd.x6d.com'; + +module.exports = async (ctx) => { + let query; + + const { id = 'latest' } = ctx.params; + + const currentUrl = id === 'latest' ? baseUrl : `${baseUrl}/html/${id}.html`; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + $('i.rj').remove(); + + if (id === 'latest') { + query = $('#newslist ul') + .eq(0) + .find('li') + .not('.addd') + .find('a') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 22); + } else { + query = $('a.soft-title').slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10); + } + + const list = query.toArray().map((item) => { + item = $(item); + return { + title: item.text(), + link: `${baseUrl}${item.attr('href')}`, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + const content = cheerio.load(detailResponse); + + item.description = content('div.article-content').html(); + item.pubDate = timezone(parseDate(content('time').text()), 8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `小刀娱乐网 - ${$('title').text().split('-')[0]}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/x6d/maintainer.js b/lib/v2/x6d/maintainer.js new file mode 100644 index 0000000000..77e7f46e2f --- /dev/null +++ b/lib/v2/x6d/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id?': ['nczitzk'], +}; diff --git a/lib/v2/x6d/radar.js b/lib/v2/x6d/radar.js new file mode 100644 index 0000000000..f83562613e --- /dev/null +++ b/lib/v2/x6d/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'x6d.com': { + _name: '小刀娱乐网', + xd: [ + { + title: '最新', + docs: 'https://docs.rsshub.app/new-media.html#xiao-dao-yu-le-wang', + source: ['/html/:id'], + target: (params) => `/x6d/${params.id.replace('.html', '')}`, + }, + ], + }, +}; diff --git a/lib/v2/x6d/router.js b/lib/v2/x6d/router.js new file mode 100644 index 0000000000..2353c905f1 --- /dev/null +++ b/lib/v2/x6d/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:id?', require('./index')); +};