fix(route): 恩山无线论坛使用UTF-8编码 (#12451)
* fix(route): 恩山无线论坛使用UTF-8编码 * remove v1 route
This commit is contained in:
+1
-1
@@ -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 中找到,默认为新手入门及其它(硬件)']"/>
|
||||
|
||||
## 二次元虫洞
|
||||
|
||||
|
||||
+1
-1
@@ -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'));
|
||||
|
||||
@@ -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;
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/forum/:id?': ['nczitzk'],
|
||||
};
|
||||
@@ -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]}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/forum/:id?', require('./forum'));
|
||||
};
|
||||
Reference in New Issue
Block a user