diff --git a/docs/bbs.md b/docs/bbs.md index 074c655afe..1d2a687948 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -244,6 +244,12 @@ pageClass: routes +## 恩山无线论坛 + +### 板块 + + + ## 光谷社区 ### 子论坛 diff --git a/lib/router.js b/lib/router.js index b2bbf81bb7..ae1e818cf7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4158,6 +4158,9 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese')); // Harvard router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog')); +// 恩山无线论坛 +router.get('/right/forum/:id?', require('./routes/right/forum')); + // 生物探索 router.get('/biodiscover/:channel?', require('./routes/biodiscover')); diff --git a/lib/routes/right/forum.js b/lib/routes/right/forum.js new file mode 100644 index 0000000000..e70fec9e19 --- /dev/null +++ b/lib/routes/right/forum.js @@ -0,0 +1,68 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const id = ctx.params.id || '31'; + + const rootUrl = 'https://www.right.com.cn'; + const currentUrl = `${rootUrl}/forum/forum-${id}-1.html`; + const response = await got({ + method: 'get', + url: currentUrl, + responseType: 'buffer', + }); + + const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + + $('a[title="隐藏置顶帖"]').each(function () { + $(this).parents('tbody').remove(); + }); + + const list = $('.s') + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}/forum/${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + responseType: 'buffer', + }); + + detailResponse.data = iconv.decode(detailResponse.data, 'gbk'); + const postId = detailResponse.data.match(/
/)[1]; + const content = cheerio.load(detailResponse.data); + + item.author = content('.authi').eq(0).text(); + item.description = content('#postmessage_' + postId).html(); + item.pubDate = timezone( + new Date( + content('#authorposton' + postId) + .text() + .replace('发表于 ', '') + ), + +8 + ); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.xs2 a').text()} - 恩山无线论坛`, + link: currentUrl, + item: items, + }; +};