Skip to content

Commit dc61635

Browse files
authored
Merge pull request #1031 from DIYgod/master
[pull] master from diygod:master
2 parents d6376af + 1af5ddc commit dc61635

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2495
-1313
lines changed

.github/workflows/docs-search-index.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- master
77
paths:
88
- '.github/workflows/docs-search-index.yml'
9+
- 'scripts/docs-scraper/docs.rsshub.app.json'
910
- 'website/**'
1011
workflow_dispatch: ~
1112
schedule:

lib/config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const calculateValue = () => {
1010
const email_config = {};
1111
const discuz_cookies = {};
1212
const medium_cookies = {};
13+
const discourse_config = {};
1314

1415
for (const name in envs) {
1516
if (name.startsWith('BILIBILI_COOKIE_')) {
@@ -27,6 +28,9 @@ const calculateValue = () => {
2728
} else if (name.startsWith('MEDIUM_COOKIE_')) {
2829
const username = name.slice(14).toLowerCase();
2930
medium_cookies[username] = envs[name];
31+
} else if (name.startsWith('DISCOURSE_CONFIG_')) {
32+
const id = name.slice('DISCOURSE_CONFIG_'.length);
33+
discourse_config[id] = JSON.parse(envs[name]);
3034
}
3135
}
3236

@@ -136,6 +140,9 @@ const calculateValue = () => {
136140
discord: {
137141
authorization: envs.DISCORD_AUTHORIZATION,
138142
},
143+
discourse: {
144+
config: discourse_config,
145+
},
139146
discuz: {
140147
cookies: discuz_cookies,
141148
},
@@ -275,6 +282,9 @@ const calculateValue = () => {
275282
telegram: {
276283
token: envs.TELEGRAM_TOKEN,
277284
},
285+
tophub: {
286+
cookie: envs.TOPHUB_COOKIE,
287+
},
278288
twitter: {
279289
consumer_key: envs.TWITTER_CONSUMER_KEY,
280290
consumer_secret: envs.TWITTER_CONSUMER_SECRET,

lib/radar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const fs = require('fs');
33
const toSource = require('tosource');
44
const { join } = require('path');
55

6-
const allowNamespace = ['ehentai', 'test'];
6+
// Namespaces that do not require radar.js
7+
const allowNamespace = ['discourse', 'ehentai', 'test'];
78
// Check if a radar.js file is exist under each folder of dirname
89
for (const dir of fs.readdirSync(dirname)) {
910
const dirPath = join(dirname, dir);

lib/router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@ router.get('/blogs/wordpress/:domain/:https?', lazyloadRouteHandler('./routes/bl
770770
// 西祠胡同
771771
router.get('/xici/:id?', lazyloadRouteHandler('./routes/xici'));
772772

773-
// 今日热榜
774-
router.get('/tophub/:id', lazyloadRouteHandler('./routes/tophub'));
773+
// 今日热榜 migrated to v2
774+
// router.get('/tophub/:id', lazyloadRouteHandler('./routes/tophub'));
775775

776776
// 游戏时光
777777
router.get('/vgtime/news', lazyloadRouteHandler('./routes/vgtime/news.js'));

lib/v2/baidu/maintainer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
'/gushitong/index': ['CaoMeiYouRen'],
3-
'/tieba/forum/:kw': ['u3u'],
4-
'/tieba/forum/good/:kw/:cid?': ['u3u'],
3+
'/tieba/forum/good/:kw/:cid?/:sortBy?': ['u3u'],
4+
'/tieba/forum/:kw/:sortBy?': ['u3u'],
55
'/tieba/post/:id': ['u3u'],
66
'/tieba/post/lz/:id': ['u3u'],
77
'/tieba/user/:uid': ['igxlin', 'nczitzk'],

lib/v2/baidu/router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = (router) => {
22
router.get('/gushitong/index', require('./gushitong'));
3-
router.get('/tieba/forum/:kw', require('./tieba/forum'));
4-
router.get('/tieba/forum/good/:kw/:cid?', require('./tieba/forum'));
3+
router.get('/tieba/forum/good/:kw/:cid?/:sortBy?', require('./tieba/forum'));
4+
router.get('/tieba/forum/:kw/:sortBy?', require('./tieba/forum'));
55
router.get('/tieba/post/:id', require('./tieba/post'));
66
router.get('/tieba/post/lz/:id', require('./tieba/post'));
77
router.get('/tieba/user/:uid', require('./tieba/user'));

lib/v2/baidu/tieba/forum.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const { art } = require('@/utils/render');
66
const path = require('path');
77

88
module.exports = async (ctx) => {
9-
const { kw, cid } = ctx.params;
9+
// sortBy: created, replied
10+
const { kw, cid = '0', sortBy = 'created' } = ctx.params;
1011

1112
// PC端:https://tieba.baidu.com/f?kw=${encodeURIComponent(kw)}
1213
// 移动端接口:https://tieba.baidu.com/mo/q/m?kw=${encodeURIComponent(kw)}&lp=5024&forum_recommend=1&lm=0&cid=0&has_url_param=1&pn=0&is_ajax=1
@@ -31,7 +32,7 @@ module.exports = async (ctx) => {
3132
.map((element) => {
3233
const item = $(element);
3334
const { id, author_name } = item.data('field');
34-
const time = item.find('.threadlist_reply_date').text().trim();
35+
const time = sortBy === 'created' ? item.find('.is_show_create_time').text().trim() : item.find('.threadlist_reply_date').text().trim();
3536
const title = item.find('a.j_th_tit').text().trim();
3637
const details = item.find('.threadlist_abs').text().trim();
3738
const medias = item
@@ -50,7 +51,7 @@ module.exports = async (ctx) => {
5051
medias,
5152
author_name,
5253
}),
53-
pubDate: timezone(parseDate(time, ['HH:mm', 'M-D'], true), +8),
54+
pubDate: timezone(parseDate(time, ['HH:mm', 'M-D', 'YYYY-MM'], true), +8),
5455
link: `https://tieba.baidu.com/p/${id}`,
5556
};
5657
});

lib/v2/discourse/maintainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'/:configId/posts': ['dzx-dzx'],
3+
};

lib/v2/discourse/posts.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const config = require('@/config').value;
2+
const got = require('@/utils/got');
3+
const RSSParser = require('@/utils/rss-parser');
4+
5+
module.exports = async (ctx) => {
6+
if (!config.discourse.config[ctx.params.configId]) {
7+
throw Error('Discourse RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install">relevant config</a>');
8+
}
9+
const { link, key } = config.discourse.config[ctx.params.configId];
10+
11+
const feed = await RSSParser.parseString(
12+
(
13+
await got(`${link}/posts.rss`, {
14+
headers: {
15+
'User-Api-Key': key,
16+
},
17+
})
18+
).data
19+
);
20+
21+
feed.items = feed.items.map((e) => ({
22+
description: e.content,
23+
author: e.creator,
24+
...e,
25+
}));
26+
27+
ctx.state.data = { item: feed.items, ...feed };
28+
};

lib/v2/discourse/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (router) => {
2+
router.get('/:configId/posts', require('./posts'));
3+
};

0 commit comments

Comments
 (0)