2022-02-16 15:17:25 +00:00
|
|
|
import { IUrl, IUrlFromServer } from '../../../definitions';
|
2023-12-13 15:50:03 +00:00
|
|
|
import { buildImageURL } from './buildImageURL';
|
2022-02-16 15:17:25 +00:00
|
|
|
|
|
|
|
export default (urls: IUrlFromServer[]): IUrl[] =>
|
2021-09-13 20:41:05 +00:00
|
|
|
urls
|
2022-02-16 15:17:25 +00:00
|
|
|
.filter((url: IUrlFromServer) => url.meta && !url.ignoreParse)
|
|
|
|
.map((url: IUrlFromServer, index) => {
|
|
|
|
const tmp: IUrl = {} as any;
|
2021-09-13 20:41:05 +00:00
|
|
|
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;
|
|
|
|
if (tmp.image) {
|
2023-12-13 15:50:03 +00:00
|
|
|
tmp.image = buildImageURL(url.url, tmp.image);
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
tmp.url = url.url;
|
|
|
|
return tmp;
|
|
|
|
});
|