mirror of
https://github.com/dariusk/rss-to-activitypub.git
synced 2024-11-22 17:29:19 +02:00
iframes
This commit is contained in:
parent
7cfe50605c
commit
01a8a5f336
|
@ -95,7 +95,7 @@ function transformContent(item) {
|
||||||
}
|
}
|
||||||
let $ = cheerio.load(item.content);
|
let $ = cheerio.load(item.content);
|
||||||
|
|
||||||
// look through all the links
|
// look through all the links to find images
|
||||||
let links = $('a');
|
let links = $('a');
|
||||||
let urls = [];
|
let urls = [];
|
||||||
//console.log('links', links.length);
|
//console.log('links', links.length);
|
||||||
|
@ -107,9 +107,10 @@ function transformContent(item) {
|
||||||
urls.push(url);
|
urls.push(url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// look through all the images
|
||||||
let images = $('img');
|
let images = $('img');
|
||||||
images.each((i,e) => {
|
images.each((i,e) => {
|
||||||
console.log(i,e);
|
|
||||||
let url = $(e).attr('src');
|
let url = $(e).attr('src');
|
||||||
// if there's an image, add it as a media attachment
|
// if there's an image, add it as a media attachment
|
||||||
if (url && url.match(/(http)?s?:?(\/\/[^"']*\.(?:png|jpg|jpeg|gif|png|svg))/)) {
|
if (url && url.match(/(http)?s?:?(\/\/[^"']*\.(?:png|jpg|jpeg|gif|png|svg))/)) {
|
||||||
|
@ -122,8 +123,17 @@ function transformContent(item) {
|
||||||
|
|
||||||
item.urls = urls;
|
item.urls = urls;
|
||||||
|
|
||||||
|
// find iframe embeds and turn them into links
|
||||||
|
let iframes = $('iframe');
|
||||||
|
iframes.each((i,e) => {
|
||||||
|
console.log('iframe',i,e);
|
||||||
|
let url = $(e).attr('src');
|
||||||
|
$(e).replaceWith($(`<a href="${url}">[embedded content]</a>`));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// remove multiple line breaks
|
// remove multiple line breaks
|
||||||
$('br').remove();
|
//$('br').remove();
|
||||||
$('p').each((i, el) => {
|
$('p').each((i, el) => {
|
||||||
if($(el).html().replace(/\s| /g, '').length === 0) {$(el).remove();}
|
if($(el).html().replace(/\s| /g, '').length === 0) {$(el).remove();}
|
||||||
});
|
});
|
||||||
|
@ -131,6 +141,8 @@ function transformContent(item) {
|
||||||
// couple of hacky regexes to make sure we clean up everything
|
// couple of hacky regexes to make sure we clean up everything
|
||||||
item.content = $('body').html().replace(/^(\n|\r)/,'').replace(/>\r+</,' ').replace(/ +/g, '');
|
item.content = $('body').html().replace(/^(\n|\r)/,'').replace(/>\r+</,' ').replace(/ +/g, '');
|
||||||
item.content = item.content.replace(/^(\n|\r)/,'').replace(/>\r+</,' ').replace(/ +/g, '');
|
item.content = item.content.replace(/^(\n|\r)/,'').replace(/>\r+</,' ').replace(/ +/g, '');
|
||||||
|
// remove whitespace nodes from in between paragraphs
|
||||||
|
item.content = item.content.replace(/p>\s<p/g,'p><p');
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue