feat(route): add 通信人家园 (#9215)

* feat(route): add 通信人家园

* Update lib/v2/txrjy/fornumtopic.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update docs/bbs.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/txrjy/fornumtopic.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix(route): add timezone

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
Fatpandac 2022-03-03 19:47:58 +08:00 committed by GitHub
parent 46bbe3c429
commit 07c5bfee23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 113 additions and 0 deletions

View File

@ -666,6 +666,18 @@ pageClass: routes
</Route>
## 通信人家园
### 论坛 频道
<Route author="Fatpandac" example="/txrjy/fornumtopic" path="/txrjy/fornumtopic/:channel?" :paramsDesc="['频道的 id见下表默认为最新500个主题帖']">
| 最新 500 个主题帖 | 最新 500 个回复帖 | 最新精华帖 | 最新精华帖 | 一周热帖 | 本月热帖 |
| :---------: | :---------: | :---: | :---: | :--: | :--: |
| 1 | 2 | 3 | 4 | 5 | 6 |
</Route>
## 万维读者
### 焦点新闻

View File

@ -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(/(<img.*?) src=".*?"(.*?>)/g, '$1$2')
.replace(/(<img.*?)zoomfile(.*?>)/g, '$1src$2'),
pattl: content(item)
.find('div.pattl')
.html()
?.replace(/(<img.*?) src=".*?"(.*?>)/g, '$1$2')
.replace(/(<img.*?)zoomfile(.*?>)/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,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/fornumtopic/:channel?': ['Fatpandac'],
};

17
lib/v2/txrjy/radar.js Normal file
View File

@ -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 : ''}`;
},
},
],
},
};

3
lib/v2/txrjy/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/fornumtopic/:channel?', require('./fornumtopic'));
};

View File

@ -0,0 +1,6 @@
<h4>{{ author }}</h4>
{{@ content }}
{{ if pattl }}
{{@ pattl }}
{{ /if }}
<hr>