diff --git a/assets/radar-rules.js b/assets/radar-rules.js index 137e4cc56f..6474ddca1c 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -2470,4 +2470,18 @@ }, ], }, + 'scboy.com': { + _name: 'scboy 论坛', + www: [ + { + title: '帖子', + docs: 'https://docs.rsshub.app/bbs.html#scboy', + source: '', + target: (params, url) => { + const id = url.includes('thread') ? url.split('-')[1].split('.')[0] : ''; + return id ? `/scboy/thread/${id}` : ''; + }, + }, + ], + }, }); diff --git a/docs/bbs.md b/docs/bbs.md index 392e28a726..cbd036c839 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -180,6 +180,17 @@ pageClass: routes +## SCBOY 论坛 + +### 帖子 + + + +帖子网址如果为 那么帖子 tid 就是 `1789863`。 + +访问水区需要添加环境变量 `SCBOY_BBS_TOKEN`, 详情见部署页面的配置模块。 `SCBOY_BBS_TOKEN`在cookies的`bbs_token`中。 + + ## V2EX ### 最热 / 最新主题 diff --git a/lib/config.js b/lib/config.js index bda7dc67ce..59f0e47e10 100644 --- a/lib/config.js +++ b/lib/config.js @@ -182,6 +182,9 @@ const calculateValue = () => { username: envs.DIDA365_USERNAME, password: envs.DIDA365_PASSWORD, }, + scboy: { + token: envs.SCBOY_BBS_TOKEN, + }, }; }; calculateValue(); diff --git a/lib/router.js b/lib/router.js index 2da2ee3d3c..d1360d84ba 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3766,4 +3766,7 @@ router.get('/sciencenet/blog/:type?/:time?/:sort?', require('./routes/sciencenet // DailyArt router.get('/dailyart/:language?', require('./routes/dailyart/index')); +// SCBOY +router.get('/scboy/thread/:tid', require('./routes/scboy/thread')); + module.exports = router; diff --git a/lib/routes/scboy/thread.js b/lib/routes/scboy/thread.js new file mode 100644 index 0000000000..acf87b25f8 --- /dev/null +++ b/lib/routes/scboy/thread.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const date = require('@/utils/date'); +const config = require('@/config').value; + +module.exports = async (ctx) => { + const tid = ctx.params.tid; + const link = `https://www.scboy.com/?thread-${tid}.htm`; + let cookieString = 'postlist_orderby=desc'; + if (config.scboy.token) { + cookieString = `postlist_orderby=desc; bbs_token=${config.scboy.token}`; + } + + const res = await got.get({ + method: 'get', + url: link, + responseType: 'buffer', + headers: { + Cookie: cookieString, + }, + }); + + const $ = cheerio.load(res.data); + const title = $('h4 > span:nth-of-type(1)').text(); + + const list = $('li.media.post'); + const count = []; + + for (let i = 0; i < Math.min(list.length, 30); i++) { + count.push(i); + } + + const resultItems = await Promise.all( + count.map(async (i) => { + const each = $(list[i]); + const floor = each.find('span.floor-parent').text(); + const item = { + title: `${title} #${floor ? floor : ' 热门回复'}`, + link: `https://www.scboy.com/?thread-${tid}`, + description: each.find('div.message.mt-1.break-all > div:nth-of-type(1)').html(), + author: each.find('username').text(), + pubDate: date(each.find('.date').text()), + }; + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: title, + link: `https://www.scboy.com/?thread-${tid}.htm`, + item: resultItems, + }; +};