Skip to content

Commit 06ee43f

Browse files
committed
Add structured data for homepage with JSON-LD
Introduces a JSON-LD script for schema.org WebSite data on the homepage to improve SEO. The script is conditionally rendered only for the homepage.
1 parent e834a06 commit 06ee43f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/components/Head.astro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ import Default from '@astrojs/starlight/components/Head.astro';
33
44
const pageTitle = Astro.locals.starlightRoute?.entry?.data?.title ?? 'Sprites Documentation';
55
const ogImageUrl = `https://og-images.fly.dev/image?template=sprites&text=${encodeURIComponent(pageTitle)}`;
6+
const slug = Astro.locals.starlightRoute?.slug ?? Astro.locals.starlightRoute?.id;
7+
const isHomePage = slug === '' || slug === 'index' || slug === 'index.mdx';
8+
9+
const websiteSchema = {
10+
'@context': 'https://schema.org',
11+
'@type': 'WebSite',
12+
name: 'Sprites Documentation',
13+
url: 'https://docs.sprites.dev',
14+
};
615
---
716

817
<Default {...Astro.props}><slot /></Default>
918

1019
<!-- Dynamic OG Image -->
1120
<meta property="og:image" content={ogImageUrl} />
1221
<meta name="twitter:image" content={ogImageUrl} />
22+
23+
{isHomePage && (
24+
<Fragment set:html={`<script type="application/ld+json">${JSON.stringify(websiteSchema)}</script>`} />
25+
)}

0 commit comments

Comments
 (0)