feat(route): add 其乐论坛 (#12768)

* feat(route): add 其乐论坛

* update lib/v2/keylol/radar.js

* fix: remove unnecessary type casting

---------
This commit is contained in:
Ethan Shen 2023-07-10 18:13:14 +08:00 committed by GitHub
parent f2c8f0c3fc
commit ea41fd8ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 122 additions and 0 deletions

View File

@ -775,6 +775,22 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
<Route author="hoilc" example="/cowlevel/element/1370" path="/cowlevel/element/:id" :paramsDesc="['元素 ID, 可在 URL 中找到']" radar="1" rssbud="1"/>
## 其乐
### 论坛
<Route author="nczitzk" example="/keylol" path="/keylol/:path+" :paramsDesc="['路径,默认为热点聚焦']">
::: tip 提示
若订阅 [热点聚焦](https://keylol.com/f161-1),网址为 <https://keylol.com/f161-1>。截取 `https://keylol.com/` 到末尾的部分 `f161-1` 作为参数,此时路由为 [`/keylol/f161-1`](https://rsshub.app/keylol/f161-1)。
若订阅子分类 [试玩免费 - 热点聚焦](https://keylol.com/forum.php?mod=forumdisplay&fid=161&filter=typeid&typeid=459),网址为 <https://keylol.com/forum.php?mod=forumdisplay&fid=161&filter=typeid&typeid=459>。截取 `https://keylol.com/forum.php?mod=forumdisplay&` 到末尾的部分 `fid=161&filter=typeid&typeid=459` 作为参数,此时路由为 [`/keylol/fid=161&filter=typeid&typeid=459`](https://rsshub.app/keylol/fid=161&filter=typeid&typeid=459)。
:::
</Route>
## 少女前线
### 情报局

82
lib/v2/keylol/index.js Normal file
View File

@ -0,0 +1,82 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
let thePath = ctx.path.replace(/^\//, '');
if (/^f\d+-\d+/.test(thePath)) {
thePath = `fid=${thePath.match(/^f(\d+)-\d+/)[1]}`;
}
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
const rootUrl = 'https://keylol.com';
const currentUrl = new URL(`forum.php?mod=forumdisplay&${thePath.replace(/mod=\w+&/g, '')}`, rootUrl).href;
const { data: response } = await got(currentUrl);
const $ = cheerio.load(response);
let items = $('a.xst')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: new URL(item.prop('href').split('&extra=')[0], rootUrl).href,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = cheerio.load(detailResponse);
item.description = content('td.t_f').html();
item.author = content('a.xw1').first().text();
item.category = content('#keyloL_thread_tags a')
.toArray()
.map((c) => content(c).text());
const pubDateEm = content('img.authicn').first().next();
const pubDateText = pubDateEm.find('span').prop('title') ?? pubDateEm.text();
const pubDateMatches = pubDateText.match(/(\d{4}-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2})/) ?? undefined;
if (pubDateMatches) {
item.pubDate = timezone(parseDate(pubDateMatches[1], 'YYYY-M-D HH:mm:ss'), +8);
}
const updatedMatches =
content('i.pstatus')
.text()
.match(/(\d{4}-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2})/) ?? undefined;
if (updatedMatches) {
item.updated = timezone(parseDate(updatedMatches[1], 'YYYY-M-D HH:mm:ss'), +8);
}
item.comments = content('div.subforum_right_title_left_down').text() ? parseInt(content('div.subforum_right_title_left_down').text(), 10) : 0;
return item;
})
)
);
const icon = $('link[rel="apple-touch-icon"]').prop('href');
ctx.state.data = {
item: items,
title: $('title').text(),
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh-cn',
icon,
logo: icon,
subtitle: $('meta[name="application-name"]').prop('content'),
author: $('meta[name="author"]').prop('content'),
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:path+': ['nczitzk'],
};

18
lib/v2/keylol/radar.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
'keylol.com': {
_name: '其乐',
'.': [
{
title: '论坛',
docs: 'https://docs.rsshub.app/game.html#qi-le-lun-tan',
source: ['/:category', '/'],
target: (params, url) => {
url = new URL(url);
const path = url.href.match(/keylol\.com\/(forum.php\?.*|f\d+-\d+)?/).replace(/forum.php\?/, '')[1];
return `/keylol${path ? `/${path}` : ''}`;
},
},
],
},
};

3
lib/v2/keylol/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get(/([\w-/]+)?/, require('./'));
};