mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 10:38:03 +08:00
Motivation: There are multiple routes that need to fetch articles from WeChat MP. However, letting them fetch articles by themselves could potentially lead to cache key collisions. Even if cache key collisions do not occur, un-normalized URL could potentially lead to duplicated requests. What's more, articles from WeChat MP have weird formats and need to be fixed. Creating a universal function to do this work can create some ease for new route contributors. Note: In order to make this PR atomic as much as possible, I did not touch those broken routes. Once this PR is merged, I will try to fix them. Signed-off-by: Rongrong <15956627+Rongronggg9@users.noreply.github.com>
24 lines
696 B
JavaScript
24 lines
696 B
JavaScript
const parser = require('@/utils/rss-parser');
|
|
const { finishArticleItem } = require('@/utils/wechat-mp');
|
|
|
|
module.exports = async (ctx) => {
|
|
const { id } = ctx.params;
|
|
const link = `https://github.com/hellodword/wechat-feeds/raw/feeds/${id}.xml`;
|
|
const feed = await parser.parseURL(link);
|
|
|
|
const items = feed.items.map((item) => ({
|
|
title: item.title,
|
|
pubDate: new Date(item.pubDate),
|
|
link: item.link,
|
|
guid: item.link,
|
|
}));
|
|
await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item)));
|
|
|
|
ctx.state.data = {
|
|
title: feed.title,
|
|
link,
|
|
description: feed.description,
|
|
item: items,
|
|
};
|
|
};
|