diff --git a/src/utils/getSiteInfo.ts b/src/utils/getSiteInfo.ts index d32b9ba..a5c7651 100644 --- a/src/utils/getSiteInfo.ts +++ b/src/utils/getSiteInfo.ts @@ -10,6 +10,21 @@ export interface SiteInfo { description: string } +const getIcon = (): string => { + const path = + document.querySelector('link[rel="icon" i]')?.getAttribute('href') ?? + document.querySelector('link[rel="shortcut icon" i]')?.getAttribute('href') ?? + document.querySelector('meta[property="og:image" i]')?.getAttribute('content') ?? + document.querySelector('link[rel="apple-touch-icon" i]')?.getAttribute('href') ?? + `/favicon.ico` + + if (path.startsWith('data:') || path.startsWith('//')) { + return path + } else { + return buildFullURL(document.location.origin, path) + } +} + const getSiteInfo = (): SiteInfo => { return { host: document.location.host, @@ -20,14 +35,7 @@ const getSiteInfo = (): SiteInfo => { document.querySelector('meta[property="og:site_name" i]')?.getAttribute('content') ?? document.querySelector('meta[property="og:title" i]')?.getAttribute('content') ?? document.title, - icon: buildFullURL( - document.location.origin, - document.querySelector('link[rel="icon" i]')?.getAttribute('href') ?? - document.querySelector('link[rel="shortcut icon" i]')?.getAttribute('href') ?? - document.querySelector('meta[property="og:image" i]')?.getAttribute('content') ?? - document.querySelector('link[rel="apple-touch-icon" i]')?.getAttribute('href') ?? - `/favicon.ico` - ), + icon: getIcon(), description: document.querySelector('meta[property="og:description i"]')?.getAttribute('content') ?? document.querySelector('meta[name="description" i]')?.getAttribute('content') ??