Skip to content

Commit

Permalink
Merge pull request #939 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored May 6, 2023
2 parents d0e200c + 1153afc commit d70bd4e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 26 deletions.
1 change: 1 addition & 0 deletions docs/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
strict-peer-dependencies=false
2 changes: 1 addition & 1 deletion docs/bbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ pageClass: routes

### 板块

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

## 二次元虫洞

Expand Down
2 changes: 1 addition & 1 deletion docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ GitHub 官方也提供了一些 RSS:

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

### 仓库 Contirbutors
### 仓库 Contributors

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

Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
44 changes: 21 additions & 23 deletions lib/routes/right/forum.js → lib/v2/right/forum.js
Original file line number Diff line number Diff line change
@@ -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(/<div id="post_(\d+)" >/)[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;
})
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/right/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/forum/:id?': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/right/radar.js
Original file line number Diff line number Diff line change
@@ -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]}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/right/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/forum/:id?', require('./forum'));
};

1 comment on commit d70bd4e

@vercel
Copy link

@vercel vercel bot commented on d70bd4e May 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.