feat(route): add 二次元虫洞 (#10406)
* feat(route): add 二次元虫洞 * refactor(radar): 完善二次元虫洞radar * Apply suggestions from code review 规范代码 Co-authored-by: Tony <TonyRL@users.noreply.github.com> * style: auto format * fix(route): 增加时间解析 Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix(route): 引入时间解析方法 Co-authored-by: shelken <shelken.pxk@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Tony
shelken
github-actions[bot]
parent
51b6f13340
commit
269e8bcdc9
+20
@@ -434,6 +434,26 @@ pageClass: routes
|
||||
|
||||
<Route author="nczitzk" example="/right/forum/31" path="/right/forum/:id?" :paramsDesc="['板块 id,可在板块页 URL 中找到']"/>
|
||||
|
||||
## 二次元虫洞
|
||||
|
||||
### 板块
|
||||
|
||||
<Route author="shelken" example="/2cycd/43/dateline" path="/2cycd/:fid?/:sort?" :paramsDesc="['板块', '排序']" radar="1">
|
||||
|
||||
板块(更多板块请自行 [查看](http://www.2cycd.com))
|
||||
|
||||
| 音乐下载(默认) | 动漫下载 | 游戏下载 |
|
||||
| -------- | ---- | ---- |
|
||||
| 43 | 53 | 42 |
|
||||
|
||||
排序
|
||||
|
||||
| 发布时间排序(默认) | 回复/查看 | 查看 |
|
||||
| ---------- | ------- | ----- |
|
||||
| dateline | replies | views |
|
||||
|
||||
</Route>
|
||||
|
||||
## 光谷社区
|
||||
|
||||
### 子论坛
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
// http://www.2cycd.com/forum.php?mod=forumdisplay&fid=43&orderby=dateline
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const fid = ctx.params.fid ?? '43';
|
||||
const sort = ctx.params.sort ?? 'dateline';
|
||||
|
||||
const rootUrl = 'http://www.2cycd.com/forum.php?mod=forumdisplay';
|
||||
const currentUrl = `${rootUrl}&fid=${fid}&orderby=${sort}`;
|
||||
|
||||
const response = await got(currentUrl, {
|
||||
responseType: 'buffer',
|
||||
});
|
||||
|
||||
const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
|
||||
|
||||
const list = $('tbody[id^="normalthread_"]')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const xst = item.find('a.s.xst');
|
||||
const author = item.find('td.by cite a').eq(0).text();
|
||||
return {
|
||||
title: xst.text(),
|
||||
link: xst.attr('href'),
|
||||
author,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
// console.log(list);
|
||||
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'));
|
||||
const first_post = content('td[id^="postmessage_"]').first();
|
||||
const dateobj = content('em[id^="authorposton"]').first();
|
||||
item.description = first_post.html();
|
||||
item.pubDate = timezone(parseDate(dateobj.find('span').attr('title'), 'YYYY-M-D HH:mm:ss'), +8);
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:fid/:sort?': ['shelken'],
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
'2cycd.com': {
|
||||
_name: '二次元虫洞',
|
||||
'.': [
|
||||
{
|
||||
title: '板块',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#er-ci-yuan-chong-dong',
|
||||
source: '/:path',
|
||||
target: (params, url) => {
|
||||
let pid, sort;
|
||||
const static_matched = params.path.match(/forum-(\d+)-\d+.html/);
|
||||
if (static_matched) {
|
||||
pid = static_matched[1];
|
||||
} else if (params.path === 'forum.php') {
|
||||
pid = new URL(url).searchParams.get('fid');
|
||||
sort = new URL(url).searchParams.get('orderby');
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return `/2cycd/${pid}/${sort ? sort : 'dateline'}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/:fid/:sort?', require('./index'));
|
||||
};
|
||||
Reference in New Issue
Block a user