feat: configurable favicon service URL (#659)
This commit is contained in:
parent
e544c0a801
commit
f8cca5522f
28 changed files with 151 additions and 20 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import { faviconUrl } from '@/lib/faviconUrl'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useContentPolicy } from '@/providers/ContentPolicyProvider'
|
||||
import { useState } from 'react'
|
||||
|
||||
export function Favicon({
|
||||
|
|
@ -10,15 +12,18 @@ export function Favicon({
|
|||
className?: string
|
||||
fallback?: React.ReactNode
|
||||
}) {
|
||||
const { faviconUrlTemplate } = useContentPolicy()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState(false)
|
||||
if (error) return fallback
|
||||
|
||||
const url = faviconUrl(faviconUrlTemplate, `https://${domain}`)
|
||||
|
||||
return (
|
||||
<div className={cn('relative', className)}>
|
||||
{loading && <div className={cn('absolute inset-0', className)}>{fallback}</div>}
|
||||
<img
|
||||
src={`https://${domain}/favicon.ico`}
|
||||
src={url}
|
||||
alt={domain}
|
||||
className={cn('absolute inset-0', loading && 'opacity-0', className)}
|
||||
onError={() => setError(true)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue