Merge pull request #319 from bokub/feature/favicon

Add favicon to websites
This commit is contained in:
Mike Cao 2020-10-21 15:53:48 -07:00 committed by GitHub
commit 8021d9d3fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 151 additions and 114 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;
}