diff --git a/app/[locale]/lessons/[slug]/layout.tsx b/app/[locale]/lessons/[slug]/layout.tsx index e84c8ce..8fd5f3a 100644 --- a/app/[locale]/lessons/[slug]/layout.tsx +++ b/app/[locale]/lessons/[slug]/layout.tsx @@ -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 && (