remove fallback logic, use service instead of direct URL
This commit is contained in:
1 parent
00a31c6366
commit
7e54e7de31
1 file changed
+3
-28
@@ -1,33 +1,8 @@
|
||||
import { Icon, Row, Text } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { Globe, Grid2x2, Link } from '@/components/icons';
|
||||
import { Favicon } from '@/components/common/Favicon';
|
||||
import { Grid2x2, Link } from '@/components/icons';
|
||||
import type { BoardEntityType } from '@/lib/boards';
|
||||
|
||||
const HOSTNAME_REGEX = /^(?:https?:\/\/)?(?:[^@\n]+@)?([^:/\n?=]+)/im;
|
||||
|
||||
function WebsiteIcon({ domain }: { domain?: string }) {
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
if (domain && !failed) {
|
||||
const match = domain.match(HOSTNAME_REGEX);
|
||||
const hostname = match?.[1];
|
||||
|
||||
if (hostname) {
|
||||
return (
|
||||
<img
|
||||
src={`https://${hostname}/favicon.ico`}
|
||||
width={16}
|
||||
height={16}
|
||||
alt=""
|
||||
onError={() => setFailed(true)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return <Globe width={16} height={16} />;
|
||||
}
|
||||
|
||||
export function BoardEntityBadge({
|
||||
type,
|
||||
name,
|
||||
@@ -45,7 +20,7 @@ export function BoardEntityBadge({
|
||||
) : type === 'link' ? (
|
||||
<Link />
|
||||
) : (
|
||||
<WebsiteIcon domain={domain} />
|
||||
<Favicon domain={domain} />
|
||||
)}
|
||||
</Icon>
|
||||
<Text size="sm">{name}</Text>
|
||||
|
||||
Reference in new issue
Block a user