fix: separate JSON-LD @graph into individual scripts with own @context

This commit is contained in:
AyrisAI
2026-07-25 11:27:45 +03:00
parent 72631e2aad
commit b1fd19d2fd
+22 -15
View File
@@ -58,23 +58,21 @@ export default async function LessonDetailLayout({
const { slug, locale } = await params; const { slug, locale } = await params;
const lesson = await getLessonBySlug(slug); const lesson = await getLessonBySlug(slug);
const jsonLd = lesson const videoSchema = lesson
? { ? {
'@context': 'https://schema.org', '@context': 'https://schema.org',
'@graph': [
{
'@type': 'VideoObject', '@type': 'VideoObject',
name: lesson.title, name: lesson.title,
description: lesson.summary || lesson.title, description: lesson.summary || lesson.title,
thumbnailUrl: lesson.thumbnailUrl || '', thumbnailUrl: lesson.thumbnailUrl || '',
uploadDate: lesson.createdAt || new Date().toISOString(), uploadDate: lesson.createdAt || new Date().toISOString(),
duration: lesson.duration ...(lesson.duration && {
? `PT${lesson.duration.replace(':', 'M')}S` duration: `PT${lesson.duration.replace(':', 'M')}S`,
: undefined, }),
contentUrl: lesson.youtubeUrl || '', contentUrl: lesson.youtubeUrl || '',
embedUrl: lesson.youtubeId ...(lesson.youtubeId && {
? `https://www.youtube.com/embed/${lesson.youtubeId}` embedUrl: `https://www.youtube.com/embed/${lesson.youtubeId}`,
: undefined, }),
author: { '@type': 'Person', name: 'ayris.tech', url: BASE_URL }, author: { '@type': 'Person', name: 'ayris.tech', url: BASE_URL },
publisher: { publisher: {
'@type': 'Organization', '@type': 'Organization',
@@ -82,26 +80,35 @@ export default async function LessonDetailLayout({
url: BASE_URL, url: BASE_URL,
logo: { '@type': 'ImageObject', url: `${BASE_URL}/logo.jpeg` }, logo: { '@type': 'ImageObject', url: `${BASE_URL}/logo.jpeg` },
}, },
}, }
{ : null;
const breadcrumbSchema = lesson
? {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList', '@type': 'BreadcrumbList',
itemListElement: [ itemListElement: [
{ '@type': 'ListItem', position: 1, name: 'Home', item: `${BASE_URL}/${locale}` }, { '@type': 'ListItem', position: 1, name: 'Home', item: `${BASE_URL}/${locale}` },
{ '@type': 'ListItem', position: 2, name: 'Lessons', item: `${BASE_URL}/${locale}/lessons` }, { '@type': 'ListItem', position: 2, name: 'Lessons', item: `${BASE_URL}/${locale}/lessons` },
{ '@type': 'ListItem', position: 3, name: lesson.title, item: `${BASE_URL}/${locale}/lessons/${slug}` }, { '@type': 'ListItem', position: 3, name: lesson.title, item: `${BASE_URL}/${locale}/lessons/${slug}` },
], ],
},
],
} }
: null; : null;
return ( return (
<> <>
{jsonLd && ( {videoSchema && (
<script <script
type="application/ld+json" type="application/ld+json"
suppressHydrationWarning suppressHydrationWarning
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} dangerouslySetInnerHTML={{ __html: JSON.stringify(videoSchema) }}
/>
)}
{breadcrumbSchema && (
<script
type="application/ld+json"
suppressHydrationWarning
dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbSchema) }}
/> />
)} )}
{children} {children}