Add favicon to websites

This commit is contained in:
Boris Kubiak 2020-10-21 15:44:43 +02:00
parent e55d03cbea
commit 90fa656d40
8 changed files with 44 additions and 7 deletions

View file

@ -0,0 +1,21 @@
import React from 'react';
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;
}
export default function Favicon({ domain, ...props }) {
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;
}

View file

@ -0,0 +1,3 @@
.favicon {
margin-right: 8px;
}