2018-04-24 19:34:03 +00:00
|
|
|
export default urls => urls.filter(url => url.meta && !url.ignoreParse).map((url, index) => {
|
|
|
|
const tmp = {};
|
|
|
|
const { meta } = url;
|
|
|
|
tmp._id = index;
|
|
|
|
tmp.title = meta.ogTitle || meta.twitterTitle || meta.title || meta.pageTitle || meta.oembedTitle;
|
|
|
|
tmp.description = meta.ogDescription || meta.twitterDescription || meta.description || meta.oembedAuthorName;
|
|
|
|
let decodedOgImage;
|
|
|
|
if (meta.ogImage) {
|
|
|
|
decodedOgImage = meta.ogImage.replace(/&/g, '&');
|
|
|
|
}
|
|
|
|
tmp.image = decodedOgImage || meta.twitterImage || meta.oembedThumbnailUrl;
|
2019-11-07 14:59:17 +00:00
|
|
|
if (tmp.image) {
|
|
|
|
if (tmp.image.indexOf('//') === 0) {
|
|
|
|
tmp.image = `${ url.parsedUrl.protocol }${ tmp.image }`;
|
|
|
|
} else if (tmp.image.indexOf('/') === 0 && (url.parsedUrl && url.parsedUrl.host)) {
|
|
|
|
tmp.image = `${ url.parsedUrl.protocol }//${ url.parsedUrl.host }${ tmp.image }`;
|
|
|
|
}
|
2019-11-07 12:35:04 +00:00
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
tmp.url = url.url;
|
|
|
|
return tmp;
|
|
|
|
});
|