diff --git a/docs/.npmrc b/docs/.npmrc new file mode 100644 index 00000000000000..319e41e69dc981 --- /dev/null +++ b/docs/.npmrc @@ -0,0 +1 @@ +strict-peer-dependencies=false diff --git a/docs/bbs.md b/docs/bbs.md index aeee770927f205..e043c6467f5845 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -527,7 +527,7 @@ pageClass: routes ### 板块 - + ## 二次元虫洞 diff --git a/docs/programming.md b/docs/programming.md index b8e2aeef3392ea..daf3f6590bcf0f 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -302,7 +302,7 @@ GitHub 官方也提供了一些 RSS: -### 仓库 Contirbutors +### 仓库 Contributors diff --git a/lib/router.js b/lib/router.js index 29e49bb1dbfd67..966b9da76f2cc3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3979,7 +3979,7 @@ router.get('/fnal/news/:category?', lazyloadRouteHandler('./routes/fnal/news')); router.get('/x410/news', lazyloadRouteHandler('./routes/x410/news')); // 恩山无线论坛 -router.get('/right/forum/:id?', lazyloadRouteHandler('./routes/right/forum')); +// router.get('/right/forum/:id?', lazyloadRouteHandler('./routes/right/forum')); // 香港經濟日報 migrated to v2 // router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index')); diff --git a/lib/routes/right/forum.js b/lib/v2/right/forum.js similarity index 53% rename from lib/routes/right/forum.js rename to lib/v2/right/forum.js index f0fa764595cd12..481cecc761fc21 100644 --- a/lib/routes/right/forum.js +++ b/lib/v2/right/forum.js @@ -1,58 +1,56 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const iconv = require('iconv-lite'); const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const id = ctx.params.id || '31'; + const id = ctx.params.id ?? '31'; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20; 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')); + const $ = cheerio.load(response.data); $('a[title="隐藏置顶帖"]').each(function () { $(this).parents('tbody').remove(); }); - const list = $('.s') - .map((_, item) => { + let items = $('.s') + .slice(0, limit) + .toArray() + .map((item) => { item = $(item); + return { title: item.text(), link: `${rootUrl}/forum/${item.attr('href')}`, }; - }) - .get(); + }); - const items = await Promise.all( - list.map((item) => + items = await Promise.all( + items.map((item) => 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 - ); + content('.pstatus').remove(); + + item.author = content('.authi').first().text(); + item.description = content('.t_f').first().html(); + item.pubDate = timezone(parseDate(content('.authi em').first().text().replace('发表于 ', '')), +8); + item.category = content('.ptg a') + .toArray() + .map((a) => content(a).text()); return item; }) diff --git a/lib/v2/right/maintainer.js b/lib/v2/right/maintainer.js new file mode 100644 index 00000000000000..e53818675ed630 --- /dev/null +++ b/lib/v2/right/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/forum/:id?': ['nczitzk'], +}; diff --git a/lib/v2/right/radar.js b/lib/v2/right/radar.js new file mode 100644 index 00000000000000..4d54d1c0df9a36 --- /dev/null +++ b/lib/v2/right/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'right.com.cn': { + _name: '恩山无线论坛', + '.': [ + { + title: '板块', + docs: 'https://docs.rsshub.app/bbs.html#en-shan-wu-xian-lun-tan', + source: ['/forum', '/'], + target: (params, url) => `/right/forum/${new URL(url).href.match(/\/forum-(\d+)-\d+.html/)[1]}`, + }, + ], + }, +}; diff --git a/lib/v2/right/router.js b/lib/v2/right/router.js new file mode 100644 index 00000000000000..6d2c00761a0da3 --- /dev/null +++ b/lib/v2/right/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/forum/:id?', require('./forum')); +};