Files
RSSHub/lib/v2/discourse/posts.js
Andvari 657c67ec37 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

---------
2023-08-23 21:19:45 +08:00

29 lines
835 B
JavaScript

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 };
};