From 569c630ca62adc4ee4b0966408057833fa5c2fbd Mon Sep 17 00:00:00 2001 From: Jack Bryant Date: Tue, 7 Mar 2023 20:49:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=94=AF=E6=8C=81=20xsijishe.co?= =?UTF-8?q?m=20=E8=AE=BA=E5=9D=9B=20rss=20(#12043)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 支持司机社论坛 rss * rename sjs to xsijishe * Update docs/bbs.md * Update docs/bbs.md * Update lib/v2/xsijishe/forum.js * Update lib/v2/xsijishe/forum.js * Update lib/v2/xsijishe/forum.js * Update lib/v2/xsijishe/radar.js --------- --- docs/bbs.md | 14 ++++++++ lib/v2/xsijishe/forum.js | 61 +++++++++++++++++++++++++++++++++++ lib/v2/xsijishe/maintainer.js | 3 ++ lib/v2/xsijishe/radar.js | 19 +++++++++++ lib/v2/xsijishe/router.js | 3 ++ 5 files changed, 100 insertions(+) create mode 100644 lib/v2/xsijishe/forum.js create mode 100644 lib/v2/xsijishe/maintainer.js create mode 100644 lib/v2/xsijishe/radar.js create mode 100644 lib/v2/xsijishe/router.js diff --git a/docs/bbs.md b/docs/bbs.md index 3f5323b01..c212696a1 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -869,6 +869,20 @@ pageClass: routes +## 司机社 + +### 论坛 + + + +::: tip 关于子论坛 id 的获取方法 + +`/xsijishe/forum/51` 对应于论坛 ,这个论坛的 fid 为 51,也就是 `forum-{fid}-1` 中的 fid。 + +::: + + + ## 天涯论坛 ### 子版块 diff --git a/lib/v2/xsijishe/forum.js b/lib/v2/xsijishe/forum.js new file mode 100644 index 000000000..91f7b839f --- /dev/null +++ b/lib/v2/xsijishe/forum.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const baseUrl = 'https://xsijishe.com'; + +module.exports = async (ctx) => { + const fid = ctx.params.fid; + const url = `${baseUrl}/forum-${fid}-1.html`; + const resp = await got(url); + const $ = cheerio.load(resp.data); + const forumCategory = $('.nex_bkinterls_top .nex_bkinterls_ls a').text(); + let items = $('[id^="normalthread"]') + .toArray() + .map((item) => { + item = $(item); + const nexAuthorBtms = item.find('.nex_author_btms'); + const nexForumtitTopA = item.find('.nex_forumtit_top a').first(); + const nexFtdate = nexAuthorBtms.find('.nex_ftdate'); + let pubDate; + if (nexFtdate.find('span').length > 0) { + pubDate = nexFtdate.find('span').attr('title'); + } else { + pubDate = nexFtdate.text().replace('发表于', ''); + } + return { + title: nexForumtitTopA.text().trim(), + pubDate: parseDate(pubDate.trim()), + category: nexAuthorBtms.find('em a').text().trim(), + link: baseUrl + '/' + nexForumtitTopA.attr('href'), + author: item.find('.nex_threads_author').find('a').text().trim(), + }; + }); + 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: `司机社${forumCategory}论坛`, + link: url, + description: `司机社${forumCategory}论坛`, + item: items, + }; +}; diff --git a/lib/v2/xsijishe/maintainer.js b/lib/v2/xsijishe/maintainer.js new file mode 100644 index 000000000..e136abf72 --- /dev/null +++ b/lib/v2/xsijishe/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/forum/:fid': ['akynazh'], +}; diff --git a/lib/v2/xsijishe/radar.js b/lib/v2/xsijishe/radar.js new file mode 100644 index 000000000..e0423fa34 --- /dev/null +++ b/lib/v2/xsijishe/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'xsijishe.com': { + _name: '司机社', + '.': [ + { + title: '论坛', + docs: 'https://docs.rsshub.app/bbs.html#si-ji-she', + source: ['/*'], + target: (_, url) => { + const re = /forum-(\d+)-/; + const res = re.exec(url); + if (res) { + return `/xsijishe/forum/${res[1]}`; + } + }, + }, + ], + }, +}; diff --git a/lib/v2/xsijishe/router.js b/lib/v2/xsijishe/router.js new file mode 100644 index 000000000..87b792c18 --- /dev/null +++ b/lib/v2/xsijishe/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/forum/:fid', require('./forum')); +};