mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 19:59:54 +08:00
* refactor: add no-implicit-coercion rule for ESLint * fix: errors from deepscan * fix: errors from deepscan * fix: errors from deepscan * fix: errors from deepscan * fix: errors from deepscan * Update docs/en/joinus/quick-start.md Co-authored-by: Sukka <isukkaw@gmail.com> * Update docs/joinus/quick-start.md Co-authored-by: Sukka <isukkaw@gmail.com> * Update lib/routes/av01/tag.js Co-authored-by: Sukka <isukkaw@gmail.com> * Update lib/routes/gov/taiwan/mnd.js Co-authored-by: Sukka <isukkaw@gmail.com> * Update lib/routes/ps/product.js Co-authored-by: Sukka <isukkaw@gmail.com> * refactor: minify html string Co-authored-by: Sukka <isukkaw@gmail.com>
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
const parser = require('@/utils/rss-parser');
|
|
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
|
|
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 = await Promise.all(
|
|
feed.items.map(async (item) => {
|
|
const cache = await ctx.cache.get(item.link);
|
|
if (cache) {
|
|
return Promise.resolve(JSON.parse(cache));
|
|
}
|
|
|
|
const response = await got.get(item.link);
|
|
|
|
const $ = cheerio.load(response.data);
|
|
const post = $('#js_content');
|
|
|
|
post.find('img').each((_, img) => {
|
|
const dataSrc = $(img).attr('data-src');
|
|
if (dataSrc) {
|
|
$(img).attr('src', dataSrc);
|
|
}
|
|
});
|
|
|
|
const single = {
|
|
title: item.title,
|
|
description: post.html(),
|
|
pubDate: new Date(item.pubDate),
|
|
link: item.link,
|
|
};
|
|
|
|
ctx.cache.set(item.link, JSON.stringify(single));
|
|
return Promise.resolve(single);
|
|
})
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: feed.title,
|
|
link,
|
|
description: feed.description,
|
|
item: items,
|
|
};
|
|
};
|