2020-10-21 15:44:43 +02:00
|
|
|
import styles from './Favicon.module.css';
|
|
|
|
|
|
|
|
function getHostName(url) {
|
|
|
|
const match = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:/\n?=]+)/im);
|
|
|
|
return match && match.length > 1 ? match[1] : null;
|
|
|
|
}
|
|
|
|
|
2021-02-16 13:04:35 +01:00
|
|
|
function Favicon({ domain, ...props }) {
|
2020-10-21 15:44:43 +02:00
|
|
|
const hostName = domain ? getHostName(domain) : null;
|
|
|
|
|
|
|
|
return hostName ? (
|
|
|
|
<img
|
|
|
|
className={styles.favicon}
|
|
|
|
src={`https://icons.duckduckgo.com/ip3/${hostName}.ico`}
|
|
|
|
height="16"
|
|
|
|
alt=""
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
) : null;
|
|
|
|
}
|
2021-02-16 13:04:35 +01:00
|
|
|
|
|
|
|
export default Favicon;
|