feat(seo): JSON-LD for movies, series, persons, website
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd34f4eb5f
commit
ce630cd029
4 files changed
+64
-12
No files matched your search
@@ -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 (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<JsonLd data={{ '@context': 'https://schema.org', '@type': 'WebSite', name: TITLE, url: SITE_URL }} />
|
||||
<h1 className='sr-only'>{TITLE} — Discover Your Next Favorite Movie</h1>
|
||||
<Container page={page} />
|
||||
</HydrationBoundary>
|
||||
|
||||
@@ -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 (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<JsonLd data={jsonLd} />
|
||||
<Container showId={showId} showType={showType} />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
|
||||
@@ -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<Metad
|
||||
const PersonPage: FC<Props> = 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 (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<JsonLd data={jsonLd} />
|
||||
<Person personId={id} />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
interface Props {
|
||||
data: Record<string, unknown>;
|
||||
}
|
||||
|
||||
const JsonLd: FC<Props> = ({ data }) => (
|
||||
<script
|
||||
type='application/ld+json'
|
||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(data).replace(/</g, '\\u003c') }}
|
||||
/>
|
||||
);
|
||||
|
||||
export default JsonLd;
|
||||
Reference in new issue
Block a user