Skip to content

Commit

Permalink
feat(route): 支持 xsijishe.com 论坛 rss (DIYgod#12043)
Browse files Browse the repository at this point in the history
* 支持司机社论坛 rss

* rename sjs to xsijishe

* Update docs/bbs.md

* Update docs/bbs.md

* Update lib/v2/xsijishe/forum.js

* Update lib/v2/xsijishe/forum.js

* Update lib/v2/xsijishe/forum.js

* Update lib/v2/xsijishe/radar.js
---------
  • Loading branch information
Jack Bryant authored Mar 7, 2023
1 parent 53cc4ca commit 569c630
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/bbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,20 @@ pageClass: routes

<Route author="nczitzk" example="/newsmth/account/fef705ec94819a5a87941759e33c0982" path="/newsmth/account/:id" :paramsDesc="['用户 id,可在用户页的 URL 中找到']"/>

## 司机社

### 论坛

<Route author="akynazh" example="/xsijishe/forum/51" path="/xsijishe/forum/:fid" :paramDesc="['子论坛 id']" radar="1">

::: tip 关于子论坛 id 的获取方法

`/xsijishe/forum/51` 对应于论坛 <https://xsijishe.com/forum-51-1.html>,这个论坛的 fid 为 51,也就是 `forum-{fid}-1` 中的 fid。

:::

</Route>

## 天涯论坛

### 子版块
Expand Down
61 changes: 61 additions & 0 deletions lib/v2/xsijishe/forum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'https://xsijishe.com';

module.exports = async (ctx) => {
const fid = ctx.params.fid;
const url = `${baseUrl}/forum-${fid}-1.html`;
const resp = await got(url);
const $ = cheerio.load(resp.data);
const forumCategory = $('.nex_bkinterls_top .nex_bkinterls_ls a').text();
let items = $('[id^="normalthread"]')
.toArray()
.map((item) => {
item = $(item);
const nexAuthorBtms = item.find('.nex_author_btms');
const nexForumtitTopA = item.find('.nex_forumtit_top a').first();
const nexFtdate = nexAuthorBtms.find('.nex_ftdate');
let pubDate;
if (nexFtdate.find('span').length > 0) {
pubDate = nexFtdate.find('span').attr('title');
} else {
pubDate = nexFtdate.text().replace('发表于', '');
}
return {
title: nexForumtitTopA.text().trim(),
pubDate: parseDate(pubDate.trim()),
category: nexAuthorBtms.find('em a').text().trim(),
link: baseUrl + '/' + nexForumtitTopA.attr('href'),
author: item.find('.nex_threads_author').find('a').text().trim(),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const resp = await got(item.link);
const $ = cheerio.load(resp.data);
const firstViewBox = $('.t_f').first();

firstViewBox.find('img').each((_, img) => {
img = $(img);
if (img.attr('zoomfile')) {
img.attr('src', img.attr('zoomfile'));
img.removeAttr('zoomfile');
img.removeAttr('file');
}
img.removeAttr('onmouseover');
});

item.description = firstViewBox.html();
return item;
})
)
);
ctx.state.data = {
title: `司机社${forumCategory}论坛`,
link: url,
description: `司机社${forumCategory}论坛`,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/xsijishe/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/forum/:fid': ['akynazh'],
};
19 changes: 19 additions & 0 deletions lib/v2/xsijishe/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'xsijishe.com': {
_name: '司机社',
'.': [
{
title: '论坛',
docs: 'https://docs.rsshub.app/bbs.html#si-ji-she',
source: ['/*'],
target: (_, url) => {
const re = /forum-(\d+)-/;
const res = re.exec(url);
if (res) {
return `/xsijishe/forum/${res[1]}`;
}
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/xsijishe/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/forum/:fid', require('./forum'));
};

0 comments on commit 569c630

Please sign in to comment.