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 { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
import JsonLd from '@/components/JsonLd';
|
||||||
import randomQuery, { generatePage } from '@/data/queries/random';
|
import randomQuery, { generatePage } from '@/data/queries/random';
|
||||||
import { TITLE } from '@/env';
|
import { SITE_URL, TITLE } from '@/env';
|
||||||
import getQueryClient from '@/lib/queryClient';
|
import getQueryClient from '@/lib/queryClient';
|
||||||
|
|
||||||
import Container from './container';
|
import Container from './container';
|
||||||
@@ -20,6 +21,7 @@ const Random = async () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
<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>
|
<h1 className='sr-only'>{TITLE} — Discover Your Next Favorite Movie</h1>
|
||||||
<Container page={page} />
|
<Container page={page} />
|
||||||
</HydrationBoundary>
|
</HydrationBoundary>
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
|
|
||||||
|
import JsonLd from '@/components/JsonLd';
|
||||||
import detailsQuery from '@/data/queries/details';
|
import detailsQuery from '@/data/queries/details';
|
||||||
import { TITLE } from '@/env';
|
import { SITE_URL, TITLE } from '@/env';
|
||||||
import getQueryClient from '@/lib/queryClient';
|
import getQueryClient from '@/lib/queryClient';
|
||||||
|
|
||||||
import Container from './container';
|
import Container from './container';
|
||||||
@@ -46,14 +47,37 @@ export const createShowPage = (showType: Show['type']) => {
|
|||||||
|
|
||||||
const showId = Number(id);
|
const showId = Number(id);
|
||||||
|
|
||||||
try {
|
const details = await queryClient.fetchQuery(detailsQuery({ showId, showType })).catch(() => null);
|
||||||
await queryClient.fetchQuery(detailsQuery({ showId, showType }));
|
|
||||||
} catch (_) {
|
if (!details) return notFound();
|
||||||
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 (
|
return (
|
||||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||||
|
<JsonLd data={jsonLd} />
|
||||||
<Container showId={showId} showType={showType} />
|
<Container showId={showId} showType={showType} />
|
||||||
</HydrationBoundary>
|
</HydrationBoundary>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
|
|
||||||
|
import JsonLd from '@/components/JsonLd';
|
||||||
import Person from '@/components/Person';
|
import Person from '@/components/Person';
|
||||||
import personQuery from '@/data/queries/person';
|
import personQuery from '@/data/queries/person';
|
||||||
import { TITLE } from '@/env';
|
import { SITE_URL, TITLE } from '@/env';
|
||||||
import getQueryClient from '@/lib/queryClient';
|
import getQueryClient from '@/lib/queryClient';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -41,14 +42,25 @@ export const generateMetadata = async ({ params: { id } }: Props): Promise<Metad
|
|||||||
const PersonPage: FC<Props> = async ({ params: { id } }) => {
|
const PersonPage: FC<Props> = async ({ params: { id } }) => {
|
||||||
const queryClient = getQueryClient();
|
const queryClient = getQueryClient();
|
||||||
|
|
||||||
try {
|
const profile = await queryClient.fetchQuery(personQuery({ personId: id })).catch(() => null);
|
||||||
await queryClient.fetchQuery(personQuery({ personId: id }));
|
|
||||||
} catch (_) {
|
if (!profile) return notFound();
|
||||||
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 (
|
return (
|
||||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||||
|
<JsonLd data={jsonLd} />
|
||||||
<Person personId={id} />
|
<Person personId={id} />
|
||||||
</HydrationBoundary>
|
</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