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 { 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',
|
||||||
{
|
name: lesson.title,
|
||||||
'@type': 'VideoObject',
|
description: lesson.summary || lesson.title,
|
||||||
name: lesson.title,
|
thumbnailUrl: lesson.thumbnailUrl || '',
|
||||||
description: lesson.summary || lesson.title,
|
uploadDate: lesson.createdAt || new Date().toISOString(),
|
||||||
thumbnailUrl: lesson.thumbnailUrl || '',
|
...(lesson.duration && {
|
||||||
uploadDate: lesson.createdAt || new Date().toISOString(),
|
duration: `PT${lesson.duration.replace(':', 'M')}S`,
|
||||||
duration: lesson.duration
|
}),
|
||||||
? `PT${lesson.duration.replace(':', 'M')}S`
|
contentUrl: lesson.youtubeUrl || '',
|
||||||
: undefined,
|
...(lesson.youtubeId && {
|
||||||
contentUrl: lesson.youtubeUrl || '',
|
embedUrl: `https://www.youtube.com/embed/${lesson.youtubeId}`,
|
||||||
embedUrl: lesson.youtubeId
|
}),
|
||||||
? `https://www.youtube.com/embed/${lesson.youtubeId}`
|
author: { '@type': 'Person', name: 'ayris.tech', url: BASE_URL },
|
||||||
: undefined,
|
publisher: {
|
||||||
author: { '@type': 'Person', name: 'ayris.tech', url: BASE_URL },
|
'@type': 'Organization',
|
||||||
publisher: {
|
name: 'ayris.tech',
|
||||||
'@type': 'Organization',
|
url: BASE_URL,
|
||||||
name: 'ayris.tech',
|
logo: { '@type': 'ImageObject', url: `${BASE_URL}/logo.jpeg` },
|
||||||
url: BASE_URL,
|
},
|
||||||
logo: { '@type': 'ImageObject', url: `${BASE_URL}/logo.jpeg` },
|
}
|
||||||
},
|
: null;
|
||||||
},
|
|
||||||
{
|
const breadcrumbSchema = lesson
|
||||||
'@type': 'BreadcrumbList',
|
? {
|
||||||
itemListElement: [
|
'@context': 'https://schema.org',
|
||||||
{ '@type': 'ListItem', position: 1, name: 'Home', item: `${BASE_URL}/${locale}` },
|
'@type': 'BreadcrumbList',
|
||||||
{ '@type': 'ListItem', position: 2, name: 'Lessons', item: `${BASE_URL}/${locale}/lessons` },
|
itemListElement: [
|
||||||
{ '@type': 'ListItem', position: 3, name: lesson.title, item: `${BASE_URL}/${locale}/lessons/${slug}` },
|
{ '@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;
|
: 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}
|
||||||
|
|||||||
Reference in New Issue
Block a user