From ce630cd029034b628f6f79a7a013b68caa1bf995 Mon Sep 17 00:00:00 2001 From: ner Date: Fri, 7 Aug 2026 17:11:50 +0300 Subject: [PATCH] feat(seo): JSON-LD for movies, series, persons, website Co-Authored-By: Claude Fable 5 --- app/(site)/(root)/page.tsx | 4 +++- app/(site)/(show)/showPage.tsx | 36 +++++++++++++++++++++++++++------ app/(site)/person/[id]/page.tsx | 24 ++++++++++++++++------ components/JsonLd/index.tsx | 14 +++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 components/JsonLd/index.tsx diff --git a/app/(site)/(root)/page.tsx b/app/(site)/(root)/page.tsx index b05eb7d..f30b8b4 100644 --- a/app/(site)/(root)/page.tsx +++ b/app/(site)/(root)/page.tsx @@ -1,8 +1,9 @@ import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; import { Metadata } from 'next'; +import JsonLd from '@/components/JsonLd'; import randomQuery, { generatePage } from '@/data/queries/random'; -import { TITLE } from '@/env'; +import { SITE_URL, TITLE } from '@/env'; import getQueryClient from '@/lib/queryClient'; import Container from './container'; @@ -20,6 +21,7 @@ const Random = async () => { return ( +

{TITLE} — Discover Your Next Favorite Movie

diff --git a/app/(site)/(show)/showPage.tsx b/app/(site)/(show)/showPage.tsx index 7e449e9..1d964f2 100644 --- a/app/(site)/(show)/showPage.tsx +++ b/app/(site)/(show)/showPage.tsx @@ -2,8 +2,9 @@ import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; import { Metadata } from 'next'; import { notFound } from 'next/navigation'; +import JsonLd from '@/components/JsonLd'; import detailsQuery from '@/data/queries/details'; -import { TITLE } from '@/env'; +import { SITE_URL, TITLE } from '@/env'; import getQueryClient from '@/lib/queryClient'; import Container from './container'; @@ -46,14 +47,37 @@ export const createShowPage = (showType: Show['type']) => { const showId = Number(id); - try { - await queryClient.fetchQuery(detailsQuery({ showId, showType })); - } catch (_) { - return notFound(); - } + const details = await queryClient.fetchQuery(detailsQuery({ showId, showType })).catch(() => null); + + if (!details) return notFound(); + + const jsonLd = { + '@context': 'https://schema.org', + '@type': showType === 'movie' ? 'Movie' : 'TVSeries', + name: details.title, + description: details.overview || undefined, + image: details.poster['2x'] || undefined, + datePublished: details.release || undefined, + genre: details.genres?.map(({ name }) => name), + url: `${SITE_URL}/${showType}/${showId}`, + ...(showType === 'movie' && details.runtime ? { duration: `PT${details.runtime}M` } : {}), + ...(details.imdb_id ? { sameAs: `https://www.imdb.com/title/${details.imdb_id}/` } : {}), + ...(details.votes + ? { + aggregateRating: { + '@type': 'AggregateRating', + ratingValue: Math.round(details.rating * 10) / 10, + ratingCount: details.votes, + bestRating: 10, + worstRating: 0 + } + } + : {}) + }; return ( + ); diff --git a/app/(site)/person/[id]/page.tsx b/app/(site)/person/[id]/page.tsx index 2d648cf..acf722a 100644 --- a/app/(site)/person/[id]/page.tsx +++ b/app/(site)/person/[id]/page.tsx @@ -3,9 +3,10 @@ import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; import { Metadata } from 'next'; import { notFound } from 'next/navigation'; +import JsonLd from '@/components/JsonLd'; import Person from '@/components/Person'; import personQuery from '@/data/queries/person'; -import { TITLE } from '@/env'; +import { SITE_URL, TITLE } from '@/env'; import getQueryClient from '@/lib/queryClient'; interface Props { @@ -41,14 +42,25 @@ export const generateMetadata = async ({ params: { id } }: Props): Promise = async ({ params: { id } }) => { const queryClient = getQueryClient(); - try { - await queryClient.fetchQuery(personQuery({ personId: id })); - } catch (_) { - return notFound(); - } + const profile = await queryClient.fetchQuery(personQuery({ personId: id })).catch(() => null); + + if (!profile) return notFound(); + + const jsonLd = { + '@context': 'https://schema.org', + '@type': 'Person', + name: profile.name, + description: profile.biography || undefined, + image: profile.photo || undefined, + birthDate: profile.birthday || undefined, + deathDate: profile.deathday || undefined, + birthPlace: profile.birthplace ? { '@type': 'Place', name: profile.birthplace } : undefined, + url: `${SITE_URL}/person/${id}` + }; return ( + ); diff --git a/components/JsonLd/index.tsx b/components/JsonLd/index.tsx new file mode 100644 index 0000000..620532d --- /dev/null +++ b/components/JsonLd/index.tsx @@ -0,0 +1,14 @@ +import { FC } from 'react'; + +interface Props { + data: Record; +} + +const JsonLd: FC = ({ data }) => ( +