mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 01:30:33 +08:00
feat(route): Start on support for generic discourse forums. (#13063)
* Start on support for generic discourse forums. * Add doc. * Update doc. * Add exception. * Update doc. * Update bbs.md * test: add discourse config * docs: fix typo * fix: guard condition ---------
This commit is contained in:
28
lib/v2/discourse/posts.js
Normal file
28
lib/v2/discourse/posts.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const config = require('@/config').value;
|
||||
const got = require('@/utils/got');
|
||||
const RSSParser = require('@/utils/rss-parser');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
if (!config.discourse.config[ctx.params.configId]) {
|
||||
throw Error('Discourse RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install">relevant config</a>');
|
||||
}
|
||||
const { link, key } = config.discourse.config[ctx.params.configId];
|
||||
|
||||
const feed = await RSSParser.parseString(
|
||||
(
|
||||
await got(`${link}/posts.rss`, {
|
||||
headers: {
|
||||
'User-Api-Key': key,
|
||||
},
|
||||
})
|
||||
).data
|
||||
);
|
||||
|
||||
feed.items = feed.items.map((e) => ({
|
||||
description: e.content,
|
||||
author: e.creator,
|
||||
...e,
|
||||
}));
|
||||
|
||||
ctx.state.data = { item: feed.items, ...feed };
|
||||
};
|
||||
Reference in New Issue
Block a user