/* eslint-disable no-param-reassign */
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
interface FaviconProps {
alt?: string;
src: string;
}
const Favicon = ({ src, alt = 'favicon', ...attr }: FaviconProps) => (
);
interface EmbedProps {
favicon?: string;
html?: string;
iframe?: boolean;
image?: string;
lazy?: boolean;
providerName?: string;
providerUrl?: string;
title: string;
typeOfEmbed?: string;
url: string;
}
const Embed = ({
lazy = true,
url,
html,
providerName,
providerUrl,
title,
iframe,
image,
favicon,
...attrs
}: EmbedProps) => {
if (typeof iframe !== 'boolean') iframe = iframe === 'true';
if (html) {
try {
if (html !== decodeURIComponent(html)) {
html = decodeURIComponent(html);
} else if (html === 'false') {
html = undefined;
}
} catch (e) {
// html wasn't HTML apparently
html = undefined;
}
}
if (iframe) {
return ;
}
if (!providerUrl && url)
providerUrl = new URL(url).hostname
.split(/(?:www)?\./)
.filter(i => i)
.join('.');
if (!providerName) providerName = providerUrl;
const classes = ['embed', image ? 'embed_hasImg' : ''];
return (