Skip to content

Commit f3946d8

Browse files
Copilothotlong
andcommitted
feat: add JSON-LD structured data for search engines
- Add TechArticle schema to individual docs pages - Add WebSite schema to root layout - Enhances SEO with structured data for Google/search engines Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 60f6824 commit f3946d8

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

packages/site/app/[lang]/docs/[[...slug]]/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ export default async function Page({ params }: PageProps) {
3232

3333
const MDX = page.data.body;
3434

35+
const jsonLd = {
36+
'@context': 'https://schema.org',
37+
'@type': 'TechArticle',
38+
headline: page.data.title,
39+
description: page.data.description ?? '',
40+
image: getPageImage(page).url,
41+
url: `${siteConfig.meta.url}/${lang}/docs/${slug.join('/')}`,
42+
publisher: {
43+
'@type': 'Organization',
44+
name: siteConfig.meta.title,
45+
url: siteConfig.meta.url,
46+
},
47+
};
48+
3549
return (
3650
<DocsPage
3751
toc={page.data.toc}
@@ -41,6 +55,10 @@ export default async function Page({ params }: PageProps) {
4155
style: siteConfig.layout.toc.depth > 2 ? 'clerk' : 'normal',
4256
}}
4357
>
58+
<script
59+
type="application/ld+json"
60+
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
61+
/>
4462
<DocsTitle>{page.data.title}</DocsTitle>
4563
<DocsDescription>{page.data.description}</DocsDescription>
4664
<DocsBody>

packages/site/app/layout.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@
77
*/
88

99
import './global.css';
10+
import { siteConfig } from '@/lib/site-config';
1011

1112
export default function Layout({ children }: { children: React.ReactNode }) {
13+
const jsonLd = {
14+
'@context': 'https://schema.org',
15+
'@type': 'WebSite',
16+
name: siteConfig.meta.title,
17+
description: siteConfig.meta.description,
18+
url: siteConfig.meta.url,
19+
};
20+
1221
return (
1322
<html lang="en" suppressHydrationWarning>
1423
<body className="flex flex-col min-h-screen">
24+
<script
25+
type="application/ld+json"
26+
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
27+
/>
1528
{children}
1629
</body>
1730
</html>

0 commit comments

Comments
 (0)