()
| 88 | } |
| 89 | |
| 90 | function getSerpFromHead(): SerpData { |
| 91 | const title = document.title || '' |
| 92 | const url = typeof window !== 'undefined' ? window.location.href : '' |
| 93 | |
| 94 | const metaTags = Array.from(document.head.querySelectorAll('meta')) |
| 95 | const descriptionMeta = metaTags.find( |
| 96 | (m) => m.getAttribute('name')?.toLowerCase() === 'description', |
| 97 | ) |
| 98 | const description = descriptionMeta?.getAttribute('content')?.trim() || '' |
| 99 | |
| 100 | const siteNameMeta = metaTags.find( |
| 101 | (m) => m.getAttribute('property') === 'og:site_name', |
| 102 | ) |
| 103 | const siteName = |
| 104 | siteNameMeta?.getAttribute('content')?.trim() || |
| 105 | (typeof window !== 'undefined' |
| 106 | ? window.location.hostname.replace(/^www\./, '') |
| 107 | : '') |
| 108 | |
| 109 | const linkTags = Array.from(document.head.querySelectorAll('link')) |
| 110 | const iconLink = linkTags.find((l) => |
| 111 | l.getAttribute('rel')?.toLowerCase().split(/\s+/).includes('icon'), |
| 112 | ) |
| 113 | let favicon: string | null = iconLink?.getAttribute('href') || null |
| 114 | if (favicon && typeof window !== 'undefined') { |
| 115 | try { |
| 116 | favicon = new URL(favicon, url).href |
| 117 | } catch { |
| 118 | favicon = null |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return { title, description, siteName, favicon, url } |
| 123 | } |
| 124 | |
| 125 | function getSerpIssues( |
| 126 | data: SerpData, |
no outgoing calls
no test coverage detected