mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
feat: handle images and videos (#1594)
This commit is contained in:
@@ -5,6 +5,28 @@ const parser = new Parser();
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const feed = await parser.parseURL('https://www.idownloadblog.com/feed');
|
||||
|
||||
const ProcessFeed = (data) => {
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const content = $('div.post-content');
|
||||
|
||||
content.find('figure.wp-block-image ,figure.wp-block-embed-youtube, .wp-block-image > figure').each((i, e) => {
|
||||
let media = $(e).find('noscript')[0].children[0].data;
|
||||
|
||||
if ($(e).find('figcaption').length > 0) {
|
||||
const caption = $($(e).find('figcaption')[0]).html();
|
||||
|
||||
media = `<figure><img src=${$(media).attr('src')}><figcaption>${caption}</figcaption></figure>`;
|
||||
}
|
||||
|
||||
$(media).insertAfter(e);
|
||||
$(e).remove();
|
||||
});
|
||||
|
||||
return content.html();
|
||||
};
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map(async (item) => {
|
||||
const response = await axios({
|
||||
@@ -12,8 +34,7 @@ module.exports = async (ctx) => {
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const description = $('div.post-content').html();
|
||||
const description = ProcessFeed(response.data);
|
||||
|
||||
const single = {
|
||||
title: item.title,
|
||||
|
||||
Reference in New Issue
Block a user