mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
Add favicon to websites
This commit is contained in:
parent
e55d03cbea
commit
90fa656d40
8 changed files with 44 additions and 7 deletions
21
components/common/Favicon.js
Normal file
21
components/common/Favicon.js
Normal 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;
|
||||
}
|
||||
3
components/common/Favicon.module.css
Normal file
3
components/common/Favicon.module.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.favicon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue