MCPcopy Create free account
hub / github.com/TanStack/devtools / getSerpFromHead

Function getSerpFromHead

packages/devtools/src/tabs/seo-tab/serp-preview.tsx:90–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88}
89
90function 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
125function getSerpIssues(
126 data: SerpData,

Callers 1

SerpPreviewSectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected