feat(seo): crawlable show links, intercepted preview modal, real 404s

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
nerandClaude Fable 5 committed 2026-08-07 16:33:59 +03:00
1 parent 919dcf9a42
commit 25a5d535a4
21 files changed
+231 -127

No files matched your search

File renamed without changes.
+7
View File
@@ -0,0 +1,7 @@
import { createShowMetadata, createShowPage } from '../../showPage';
export const generateMetadata = createShowMetadata('movie');
const MoviePage = createShowPage('movie');
export default MoviePage;
+59
View File
@@ -0,0 +1,59 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import detailsQuery from '@/data/queries/details';
import { SITE_URL, TITLE } from '@/env';
import getQueryClient from '@/lib/queryClient';
import Container from './container';
interface Props {
params: { id: string };
}
export const createShowMetadata =
(showType: Show['type']) =>
async ({ params: { id } }: Props): Promise<Metadata> => {
const queryClient = getQueryClient();
try {
const { title, overview, poster } = await queryClient.fetchQuery(detailsQuery({ showId: Number(id), showType }));
return {
title: `${title} | ${TITLE}`,
description: overview,
openGraph: {
title,
description: overview,
images: [poster['2x']],
type: 'website',
url: `${SITE_URL}/${showType}/${id}`
}
};
} catch (_) {
return notFound();
}
};
export const createShowPage = (showType: Show['type']) => {
const ShowPage = async ({ params: { id } }: Props) => {
const queryClient = getQueryClient();
const showId = Number(id);
try {
await queryClient.fetchQuery(detailsQuery({ showId, showType }));
} catch (_) {
return notFound();
}
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<Container showId={showId} showType={showType} />
</HydrationBoundary>
);
};
return ShowPage;
};
+7
View File
@@ -0,0 +1,7 @@
import { createShowMetadata, createShowPage } from '../../showPage';
export const generateMetadata = createShowMetadata('tv');
const SeriesPage = createShowPage('tv');
export default SeriesPage;
+11
View File
@@ -0,0 +1,11 @@
import { FC } from 'react';
import PreviewModal from '../../preview';
interface Props {
params: { id: string };
}
const MovieModal: FC<Props> = ({ params: { id } }) => <PreviewModal showId={Number(id)} showType='movie' />;
export default MovieModal;
+11
View File
@@ -0,0 +1,11 @@
import { FC } from 'react';
import PreviewModal from '../../preview';
interface Props {
params: { id: string };
}
const SeriesModal: FC<Props> = ({ params: { id } }) => <PreviewModal showId={Number(id)} showType='tv' />;
export default SeriesModal;
+5
View File
@@ -0,0 +1,5 @@
// Matches every non-intercepted route so the preview modal unmounts
// when navigating elsewhere (e.g. to a person page from the credits).
const CatchAll = () => null;
export default CatchAll;
+3
View File
@@ -0,0 +1,3 @@
const Default = () => null;
export default Default;
+4
View File
@@ -0,0 +1,4 @@
// Matches the root route so the preview modal unmounts when navigating home.
const Empty = () => null;
export default Empty;
+29
View File
@@ -0,0 +1,29 @@
'use client';
import { FC } from 'react';
import { useAtomValue } from 'jotai';
import { useRouter } from 'next/navigation';
import Preview from '@/components/Preview';
import { previewSeedAtom } from '@/components/Preview/seed';
import { Modal } from '@/components/ui/dialog';
interface Props {
showId: Show['id'];
showType: Show['type'];
}
const PreviewModal: FC<Props> = ({ showId, showType }) => {
const router = useRouter();
const seed = useAtomValue(previewSeedAtom);
const show = seed?.id === showId && seed?.type === showType ? seed : undefined;
return (
<Modal className='block bg-background p-0 md:bg-black' onClose={() => router.back()}>
<Preview modal show={show} showId={showId} showType={showType} />
</Modal>
);
};
export default PreviewModal;
-62
View File
@@ -1,62 +0,0 @@
import { FC } from 'react';
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { Metadata } from 'next';
import { redirect } from 'next/navigation';
import detailsQuery from '@/data/queries/details';
import { SITE_URL, TITLE } from '@/env';
import getQueryClient from '@/lib/queryClient';
import Container from './container';
interface Props {
params: { show: [Show['type'], Show['id']] };
}
export const generateMetadata = async ({ params: { show } }: Props): Promise<Metadata> => {
const queryClient = getQueryClient();
const [showType, showId] = show as [Show['type'], Show['id']];
if (!showType || !showId) return redirect('/');
try {
const { title, overview, poster } = await queryClient.fetchQuery(detailsQuery({ showId, showType }));
return {
title: `${title} | ${TITLE}`,
description: overview,
openGraph: {
title,
description: overview,
images: [poster['2x']],
type: 'website',
url: `${SITE_URL}/${showType}/${showId}`
}
};
} catch (_) {
return redirect('/');
}
};
const ShowPage: FC<Props> = async ({ params: { show } }) => {
const queryClient = getQueryClient();
const [showType, showId] = show as [Show['type'], Show['id']];
if (!showType || !showId) return redirect('/');
try {
await queryClient.fetchQuery(detailsQuery({ showId, showType }));
} catch (_) {
return redirect('/');
}
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<Container showId={showId} showType={showType} />
</HydrationBoundary>
);
};
export default ShowPage;
+10
View File
@@ -0,0 +1,10 @@
import { ReactNode } from 'react';
const SiteLayout = ({ children, modal }: { children: ReactNode; modal: ReactNode }) => (
<>
{children}
{modal}
</>
);
export default SiteLayout;
+2 -4
View File
@@ -1,7 +1,7 @@
import { FC } from 'react';
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { Metadata } from 'next';
import { redirect } from 'next/navigation';
import { notFound } from 'next/navigation';
import Person from '@/components/Person';
import personQuery from '@/data/queries/person';
@@ -32,15 +32,13 @@ export const generateMetadata = async ({ params: { id } }: Props): Promise<Metad
}
};
} catch (_) {
return { title: TITLE };
return notFound();
}
};
const PersonPage: FC<Props> = async ({ params: { id } }) => {
const queryClient = getQueryClient();
if (!id) return redirect('/');
queryClient.prefetchQuery(personQuery({ personId: id }));
return (
+15
View File
@@ -0,0 +1,15 @@
import Link from 'next/link';
import { Button } from '@/components/ui/button';
const NotFound = () => (
<div className='flex flex-1 flex-col items-center justify-center gap-4 py-24 text-center'>
<span className='text-6xl'>404</span>
<p className='text-muted-foreground'>We couldn’t find that page, movie, or series.</p>
<Button asChild variant='outline'>
<Link href='/'>Back to home</Link>
</Button>
</div>
);
export default NotFound;