From 8b10f38ea029d0fc4e6ec7eac5358a573243db8e Mon Sep 17 00:00:00 2001 From: Jack Bryant Date: Sun, 10 Dec 2023 22:16:51 +0800 Subject: [PATCH] feat(route): Support xsijishe rank (#14006) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 支持司机社论坛 rss * rename sjs to xsijishe * Update docs/bbs.md Co-authored-by: Tony * Update docs/bbs.md Co-authored-by: Tony * Update lib/v2/xsijishe/forum.js Co-authored-by: Tony * Update lib/v2/xsijishe/forum.js Co-authored-by: Tony * Update lib/v2/xsijishe/forum.js Co-authored-by: Tony * Update lib/v2/xsijishe/radar.js Co-authored-by: Tony * support xsijishe rank * support xsijishe rank --------- --- lib/v2/xsijishe/maintainer.js | 1 + lib/v2/xsijishe/radar.js | 12 +++++++ lib/v2/xsijishe/rank.js | 60 +++++++++++++++++++++++++++++++++++ lib/v2/xsijishe/router.js | 1 + website/docs/routes/bbs.mdx | 4 +++ 5 files changed, 78 insertions(+) create mode 100644 lib/v2/xsijishe/rank.js diff --git a/lib/v2/xsijishe/maintainer.js b/lib/v2/xsijishe/maintainer.js index e136abf725334b..2e41f775403e83 100644 --- a/lib/v2/xsijishe/maintainer.js +++ b/lib/v2/xsijishe/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/forum/:fid': ['akynazh'], + '/rank/:type': ['akynazh'], }; diff --git a/lib/v2/xsijishe/radar.js b/lib/v2/xsijishe/radar.js index 2cab0e2f8d596b..ea7380c6c86696 100644 --- a/lib/v2/xsijishe/radar.js +++ b/lib/v2/xsijishe/radar.js @@ -14,6 +14,18 @@ module.exports = { } }, }, + { + title: '周排行榜', + docs: 'https://docs.rsshub.app/routes/bbs#si-ji-she', + source: ['/*'], + target: '/xsijishe/rank/weekly', + }, + { + title: '月排行榜', + docs: 'https://docs.rsshub.app/routes/bbs#si-ji-she', + source: ['/*'], + target: '/xsijishe/rank/monthly', + }, ], }, }; diff --git a/lib/v2/xsijishe/rank.js b/lib/v2/xsijishe/rank.js new file mode 100644 index 00000000000000..600566c869a777 --- /dev/null +++ b/lib/v2/xsijishe/rank.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const baseUrl = 'https://xsijishe.com'; + +module.exports = async (ctx) => { + const rankType = ctx.params.type; + let title; + let rankId; + if (rankType === 'weekly') { + title = '司机社综合周排行榜'; + rankId = 'nex_recons_demens'; + } else if (rankType === 'monthly') { + title = '司机社综合月排行榜'; + rankId = 'nex_recons_demens1'; + } else { + throw Error('Invalid rank type'); + } + const url = `${baseUrl}/portal.php`; + const resp = await got(url); + const $ = cheerio.load(resp.data); + let items = $(`#${rankId} dd`) + .toArray() + .map((item) => { + item = $(item); + const title = item.find('h5').text().trim(); + const link = item.find('a').attr('href'); + return { + title, + link: `${baseUrl}/${link}`, + }; + }); + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const resp = await got(item.link); + const $ = cheerio.load(resp.data); + const firstViewBox = $('.t_f').first(); + + firstViewBox.find('img').each((_, img) => { + img = $(img); + if (img.attr('zoomfile')) { + img.attr('src', img.attr('zoomfile')); + img.removeAttr('zoomfile'); + img.removeAttr('file'); + } + img.removeAttr('onmouseover'); + }); + + item.description = firstViewBox.html(); + return item; + }) + ) + ); + ctx.state.data = { + title, + link: url, + description: title, + item: items, + }; +}; diff --git a/lib/v2/xsijishe/router.js b/lib/v2/xsijishe/router.js index 87b792c189aec7..93ed05c1c65c4e 100644 --- a/lib/v2/xsijishe/router.js +++ b/lib/v2/xsijishe/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { router.get('/forum/:fid', require('./forum')); + router.get('/rank/:type', require('./rank')); }; diff --git a/website/docs/routes/bbs.mdx b/website/docs/routes/bbs.mdx index 6abc27e750a8a9..4fcc447a755440 100644 --- a/website/docs/routes/bbs.mdx +++ b/website/docs/routes/bbs.mdx @@ -1005,6 +1005,10 @@ When accessing Joeyray's Bar, `SCBOY_BBS_TOKEN` needs to be filled in `environme ## 司机社 {#si-ji-she} +### 排行榜 {#si-ji-she-pai-hang-bang} + + + ### 论坛 {#si-ji-she-lun-tan}