mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): 恩山无线论坛板块 (#7365)
Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
co-authored by
NeverBehave
parent
3467bf8dbb
commit
ae51da7cae
@@ -244,6 +244,12 @@ pageClass: routes
|
||||
|
||||
<Route author="sfyumi" example="/eleduck/jobs" path="/eleduck/jobs"/>
|
||||
|
||||
## 恩山无线论坛
|
||||
|
||||
### 板块
|
||||
|
||||
<Route author="nczitzk" example="/right/forum/31" path="/right/forum/:id?" :paramsDesc="['板块 id,可在板块页 URL 中找到']"/>
|
||||
|
||||
## 光谷社区
|
||||
|
||||
### 子论坛
|
||||
|
||||
@@ -4158,6 +4158,9 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese'));
|
||||
// Harvard
|
||||
router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog'));
|
||||
|
||||
// 恩山无线论坛
|
||||
router.get('/right/forum/:id?', require('./routes/right/forum'));
|
||||
|
||||
// 生物探索
|
||||
router.get('/biodiscover/:channel?', require('./routes/biodiscover'));
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id || '31';
|
||||
|
||||
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'));
|
||||
|
||||
$('a[title="隐藏置顶帖"]').each(function () {
|
||||
$(this).parents('tbody').remove();
|
||||
});
|
||||
|
||||
const list = $('.s')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: `${rootUrl}/forum/${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await 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
|
||||
);
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('.xs2 a').text()} - 恩山无线论坛`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user