diff --git a/docs/bbs.md b/docs/bbs.md index 62052464a..a5de64673 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -666,6 +666,18 @@ pageClass: routes +## 通信人家园 + +### 论坛 频道 + + + +| 最新 500 个主题帖 | 最新 500 个回复帖 | 最新精华帖 | 最新精华帖 | 一周热帖 | 本月热帖 | +| :---------: | :---------: | :---: | :---: | :--: | :--: | +| 1 | 2 | 3 | 4 | 5 | 6 | + + + ## 万维读者 ### 焦点新闻 diff --git a/lib/v2/txrjy/fornumtopic.js b/lib/v2/txrjy/fornumtopic.js new file mode 100644 index 000000000..6cd0a3bfa --- /dev/null +++ b/lib/v2/txrjy/fornumtopic.js @@ -0,0 +1,72 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const rootUrl = 'https://www.txrjy.com'; + +module.exports = async (ctx) => { + const channel = ctx.params.channel ?? '1'; + const url = `${rootUrl}/c114-listnewtopic.php?typeid=${channel}`; + + const response = await got(url, { + responseType: 'buffer', + }); + const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const title = $('div.z > a').last().text(); + const list = $('tbody > tr') + .slice(0, 25) + .map((_, item) => ({ + title: $(item).find('td.title2').text(), + link: new URL($(item).find('td.title2 > a').attr('href'), rootUrl).href, + author: $(item).find('td.author').text(), + pubDate: timezone(parseDate($(item).find('td.dateline').text(), 'YYYY-M-D HH:mm'), +8), + category: $(item).find('td.forum').text(), + })) + .filter((_, item) => item.title) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link, { + responseType: 'buffer', + }); + const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + + item.description = content('div.c_table') + .map((_, item) => + art(path.join(__dirname, 'templates/fornumtopic.art'), { + content: content(item) + .find('td.t_f') + .find('div.a_pr') + .remove() + .end() + .html() + ?.replace(/()/g, '$1$2') + .replace(/()/g, '$1src$2'), + pattl: content(item) + .find('div.pattl') + .html() + ?.replace(/()/g, '$1$2') + .replace(/()/g, '$1src$2'), + author: content(item).find('a.xw1').text().trim(), + }) + ) + .get() + .join('\n'); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `通信人家园 - 论坛 ${title}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/txrjy/maintainer.js b/lib/v2/txrjy/maintainer.js new file mode 100644 index 000000000..8c84a836d --- /dev/null +++ b/lib/v2/txrjy/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/fornumtopic/:channel?': ['Fatpandac'], +}; diff --git a/lib/v2/txrjy/radar.js b/lib/v2/txrjy/radar.js new file mode 100644 index 000000000..22ce331b9 --- /dev/null +++ b/lib/v2/txrjy/radar.js @@ -0,0 +1,17 @@ +module.exports = { + 'txrjy.com': { + _name: '通信人家园', + '.': [ + { + title: '论坛 频道', + docs: 'https://docs.rsshub.app/bbs.html#tong-xin-ren-jia-yuan', + source: ['/c114-listnewtopic.php'], + target: (params, url) => { + const channel = new URL(url).searchParams.get('typeid'); + + return `/txrjy/fornumtopic/${channel ? channel : ''}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/txrjy/router.js b/lib/v2/txrjy/router.js new file mode 100644 index 000000000..636438ea0 --- /dev/null +++ b/lib/v2/txrjy/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/fornumtopic/:channel?', require('./fornumtopic')); +}; diff --git a/lib/v2/txrjy/templates/fornumtopic.art b/lib/v2/txrjy/templates/fornumtopic.art new file mode 100644 index 000000000..f75b8b695 --- /dev/null +++ b/lib/v2/txrjy/templates/fornumtopic.art @@ -0,0 +1,6 @@ +

{{ author }}

+{{@ content }} +{{ if pattl }} +{{@ pattl }} +{{ /if }} +