mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 12:05:41 +01:00
Resolve favicon locally (WIP)
This commit is contained in:
parent
0cb14f3f6c
commit
4688986901
13 changed files with 91 additions and 30 deletions
|
|
@ -2,27 +2,14 @@ import React from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
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;
|
||||
}
|
||||
function Favicon({ url, ...props }) {
|
||||
const faviconUrl = url ? url : '/default-favicon.png';
|
||||
|
||||
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;
|
||||
return <img className={styles.favicon} src={faviconUrl} height="16" alt="" {...props} />;
|
||||
}
|
||||
|
||||
Favicon.propTypes = {
|
||||
domain: PropTypes.string,
|
||||
url: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Favicon;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue