feat: handle images and videos (#1594)

This commit is contained in:
Henry Wang
2019-02-21 07:24:26 +00:00
committed by DIYgod
parent 6dc40ea1ec
commit 43dd1ebcf7
+23 -2
View File
@@ -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,