mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 04:11:26 +08:00
feat(route): 微信公众号新增 wechat-feeds 来源 (#7419)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
47
lib/routes/tencent/wechat/feeds.js
Normal file
47
lib/routes/tencent/wechat/feeds.js
Normal file
@@ -0,0 +1,47 @@
|
||||
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user