From 3aa43220fadd57f322028fea23237dcc8439bbd9 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 5 Jun 2022 22:00:28 +0000 Subject: [PATCH] feat(route): sis001 (#9902) feat(route): sis001 --- docs/bbs.md | 6 ++++ lib/v2/sis001/forum.js | 62 +++++++++++++++++++++++++++++++++++++ lib/v2/sis001/maintainer.js | 3 ++ lib/v2/sis001/radar.js | 13 ++++++++ lib/v2/sis001/router.js | 3 ++ 5 files changed, 87 insertions(+) create mode 100644 lib/v2/sis001/forum.js create mode 100644 lib/v2/sis001/maintainer.js create mode 100644 lib/v2/sis001/radar.js create mode 100644 lib/v2/sis001/router.js diff --git a/docs/bbs.md b/docs/bbs.md index a5f84786c..c85fad553 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -368,6 +368,12 @@ pageClass: routes +## 第一会所 + +### 子版块 + + + ## 电鸭社区 ### 工作机会 diff --git a/lib/v2/sis001/forum.js b/lib/v2/sis001/forum.js new file mode 100644 index 000000000..4b7a2046f --- /dev/null +++ b/lib/v2/sis001/forum.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const baseUrl = 'https://www.sis001.com'; + +module.exports = async (ctx) => { + const { id = 76 } = ctx.params; + const url = `${baseUrl}/forum/forum-${id}-1.html`; + + const response = await got(url); + + const $ = cheerio.load(response.data); + + let items = $('form table') + .last() + .find('tbody') + .toArray() + .slice(1) // skip first empty row + .map((item) => { + item = $(item); + return { + title: item.find('th em').text() + ' ' + item.find('span a').eq(0).text(), + link: new URL(item.find('span a').eq(0).attr('href'), `${baseUrl}/forum/`).href, + author: item.find('.author a').text(), + pubDate: parseDate(item.find('.author em').text(), 'YYYY-M-D'), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const response = await got(item.link); + const $ = cheerio.load(response.data); + + item.category = $('.posttags a') + .toArray() + .map((a) => $(a).text()); + item.pubDate = timezone( + parseDate( + $('.postinfo') + .eq(0) + .text() + .match(/发表于 (.*)\s*只看该作者/)[1], + 'YYYY-M-D HH:mm' + ), + 8 + ); + $('div[id^=postmessage_] table, fieldset, .posttags').remove(); + item.description = $('div[id^=postmessage_]').eq(0).html() + ($('.defaultpost .postattachlist').html() ?? ''); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + description: $('meta[name=description]').attr('content'), + link: url, + item: items, + }; +}; diff --git a/lib/v2/sis001/maintainer.js b/lib/v2/sis001/maintainer.js new file mode 100644 index 000000000..de81331ba --- /dev/null +++ b/lib/v2/sis001/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/forum/:id': ['TonyRL'], +}; diff --git a/lib/v2/sis001/radar.js b/lib/v2/sis001/radar.js new file mode 100644 index 000000000..62f9baf37 --- /dev/null +++ b/lib/v2/sis001/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'sis001.com': { + _name: '第一会所', + '.': [ + { + title: '子版块', + docs: 'https://docs.rsshub.app/bbs.html#di-yi-hui-suo', + source: ['/forum/:id'], + target: (params) => `/sis001/forum/${params.id.replace('forum-', '').replace('-1.html', '')}`, + }, + ], + }, +}; diff --git a/lib/v2/sis001/router.js b/lib/v2/sis001/router.js new file mode 100644 index 000000000..daf36c88f --- /dev/null +++ b/lib/v2/sis001/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/forum/:id?', require('./forum')); +};