Skip to content

Commit d70bd4e

Browse files
authored
Merge pull request #939 from DIYgod/master
[pull] master from diygod:master
2 parents d0e200c + 1153afc commit d70bd4e

File tree

8 files changed

+44
-26
lines changed

8 files changed

+44
-26
lines changed

docs/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
strict-peer-dependencies=false

docs/bbs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ pageClass: routes
527527

528528
### 板块
529529

530-
<Route author="nczitzk" example="/right/forum/31" path="/right/forum/:id?" :paramsDesc="['板块 id,可在板块页 URL 中找到']"/>
530+
<Route author="nczitzk" example="/right/forum/31" path="/right/forum/:id?" :paramsDesc="['板块 id,可在板块页 URL 中找到,默认为新手入门及其它(硬件)']"/>
531531

532532
## 二次元虫洞
533533

docs/programming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ GitHub 官方也提供了一些 RSS:
302302

303303
<Route author="LanceZhu" example="/github/starred_repos/DIYgod" path="/github/starred_repos/:user" :paramsDesc="['用户名']" radar="1" rssbud="1"/>
304304

305-
### 仓库 Contirbutors
305+
### 仓库 Contributors
306306

307307
<Route author="zoenglinghou" example="/github/contributors/DIYgod/RSSHub" path="/github/contributors/:user/:repo/:order?/:anon?" :paramsDesc="['用户名', '仓库名', 'Commit 数量排序顺序,desc和asc(默认desc降序)', '是否包括匿名用户,默认不包含,任意值包含匿名用户']" radar="1" rssbud="1"/>
308308

lib/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3979,7 +3979,7 @@ router.get('/fnal/news/:category?', lazyloadRouteHandler('./routes/fnal/news'));
39793979
router.get('/x410/news', lazyloadRouteHandler('./routes/x410/news'));
39803980

39813981
// 恩山无线论坛
3982-
router.get('/right/forum/:id?', lazyloadRouteHandler('./routes/right/forum'));
3982+
// router.get('/right/forum/:id?', lazyloadRouteHandler('./routes/right/forum'));
39833983

39843984
// 香港經濟日報 migrated to v2
39853985
// router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index'));
Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,56 @@
11
const got = require('@/utils/got');
22
const cheerio = require('cheerio');
3-
const iconv = require('iconv-lite');
43
const timezone = require('@/utils/timezone');
4+
const { parseDate } = require('@/utils/parse-date');
55

66
module.exports = async (ctx) => {
7-
const id = ctx.params.id || '31';
7+
const id = ctx.params.id ?? '31';
8+
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20;
89

910
const rootUrl = 'https://www.right.com.cn';
1011
const currentUrl = `${rootUrl}/forum/forum-${id}-1.html`;
12+
1113
const response = await got({
1214
method: 'get',
1315
url: currentUrl,
14-
responseType: 'buffer',
1516
});
1617

17-
const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
18+
const $ = cheerio.load(response.data);
1819

1920
$('a[title="隐藏置顶帖"]').each(function () {
2021
$(this).parents('tbody').remove();
2122
});
2223

23-
const list = $('.s')
24-
.map((_, item) => {
24+
let items = $('.s')
25+
.slice(0, limit)
26+
.toArray()
27+
.map((item) => {
2528
item = $(item);
29+
2630
return {
2731
title: item.text(),
2832
link: `${rootUrl}/forum/${item.attr('href')}`,
2933
};
30-
})
31-
.get();
34+
});
3235

33-
const items = await Promise.all(
34-
list.map((item) =>
36+
items = await Promise.all(
37+
items.map((item) =>
3538
ctx.cache.tryGet(item.link, async () => {
3639
const detailResponse = await got({
3740
method: 'get',
3841
url: item.link,
39-
responseType: 'buffer',
4042
});
4143

42-
detailResponse.data = iconv.decode(detailResponse.data, 'gbk');
43-
const postId = detailResponse.data.match(/<div id="post_(\d+)" >/)[1];
4444
const content = cheerio.load(detailResponse.data);
4545

46-
item.author = content('.authi').eq(0).text();
47-
item.description = content('#postmessage_' + postId).html();
48-
item.pubDate = timezone(
49-
new Date(
50-
content('#authorposton' + postId)
51-
.text()
52-
.replace('发表于 ', '')
53-
),
54-
+8
55-
);
46+
content('.pstatus').remove();
47+
48+
item.author = content('.authi').first().text();
49+
item.description = content('.t_f').first().html();
50+
item.pubDate = timezone(parseDate(content('.authi em').first().text().replace('发表于 ', '')), +8);
51+
item.category = content('.ptg a')
52+
.toArray()
53+
.map((a) => content(a).text());
5654

5755
return item;
5856
})

lib/v2/right/maintainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'/forum/:id?': ['nczitzk'],
3+
};

lib/v2/right/radar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
'right.com.cn': {
3+
_name: '恩山无线论坛',
4+
'.': [
5+
{
6+
title: '板块',
7+
docs: 'https://docs.rsshub.app/bbs.html#en-shan-wu-xian-lun-tan',
8+
source: ['/forum', '/'],
9+
target: (params, url) => `/right/forum/${new URL(url).href.match(/\/forum-(\d+)-\d+.html/)[1]}`,
10+
},
11+
],
12+
},
13+
};

lib/v2/right/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function (router) {
2+
router.get('/forum/:id?', require('./forum'));
3+
};

0 commit comments

Comments
 (0)