fix: separate JSON-LD @graph into individual scripts with own @context
This commit is contained in:
@@ -58,50 +58,57 @@ export default async function LessonDetailLayout({
|
||||
const { slug, locale } = await params;
|
||||
const lesson = await getLessonBySlug(slug);
|
||||
|
||||
const jsonLd = lesson
|
||||
const videoSchema = lesson
|
||||
? {
|
||||
'@context': 'https://schema.org',
|
||||
'@graph': [
|
||||
{
|
||||
'@type': 'VideoObject',
|
||||
name: lesson.title,
|
||||
description: lesson.summary || lesson.title,
|
||||
thumbnailUrl: lesson.thumbnailUrl || '',
|
||||
uploadDate: lesson.createdAt || new Date().toISOString(),
|
||||
duration: lesson.duration
|
||||
? `PT${lesson.duration.replace(':', 'M')}S`
|
||||
: undefined,
|
||||
contentUrl: lesson.youtubeUrl || '',
|
||||
embedUrl: lesson.youtubeId
|
||||
? `https://www.youtube.com/embed/${lesson.youtubeId}`
|
||||
: undefined,
|
||||
author: { '@type': 'Person', name: 'ayris.tech', url: BASE_URL },
|
||||
publisher: {
|
||||
'@type': 'Organization',
|
||||
name: 'ayris.tech',
|
||||
url: BASE_URL,
|
||||
logo: { '@type': 'ImageObject', url: `${BASE_URL}/logo.jpeg` },
|
||||
},
|
||||
},
|
||||
{
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: [
|
||||
{ '@type': 'ListItem', position: 1, name: 'Home', item: `${BASE_URL}/${locale}` },
|
||||
{ '@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': 'VideoObject',
|
||||
name: lesson.title,
|
||||
description: lesson.summary || lesson.title,
|
||||
thumbnailUrl: lesson.thumbnailUrl || '',
|
||||
uploadDate: lesson.createdAt || new Date().toISOString(),
|
||||
...(lesson.duration && {
|
||||
duration: `PT${lesson.duration.replace(':', 'M')}S`,
|
||||
}),
|
||||
contentUrl: lesson.youtubeUrl || '',
|
||||
...(lesson.youtubeId && {
|
||||
embedUrl: `https://www.youtube.com/embed/${lesson.youtubeId}`,
|
||||
}),
|
||||
author: { '@type': 'Person', name: 'ayris.tech', url: BASE_URL },
|
||||
publisher: {
|
||||
'@type': 'Organization',
|
||||
name: 'ayris.tech',
|
||||
url: BASE_URL,
|
||||
logo: { '@type': 'ImageObject', url: `${BASE_URL}/logo.jpeg` },
|
||||
},
|
||||
}
|
||||
: null;
|
||||
|
||||
const breadcrumbSchema = lesson
|
||||
? {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: [
|
||||
{ '@type': 'ListItem', position: 1, name: 'Home', item: `${BASE_URL}/${locale}` },
|
||||
{ '@type': 'ListItem', position: 2, name: 'Lessons', item: `${BASE_URL}/${locale}/lessons` },
|
||||
{ '@type': 'ListItem', position: 3, name: lesson.title, item: `${BASE_URL}/${locale}/lessons/${slug}` },
|
||||
],
|
||||
}
|
||||
: null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{jsonLd && (
|
||||
{videoSchema && (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
suppressHydrationWarning
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(videoSchema) }}
|
||||
/>
|
||||
)}
|
||||
{breadcrumbSchema && (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
suppressHydrationWarning
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbSchema) }}
|
||||
/>
|
||||
)}
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user