Following links reached only 37 of 1873 urls and the frontier was exhausted at depth 3, because detail pages rendered no internal links server side. - Prefetch similar shows on detail pages so their links land in the ssr html. Crawl reach goes from 37 pages to 782 and keeps growing. Credits are left client side on purpose: dehydrating aggregate_credits pushed a series page from 52kb to 600kb to surface only ten person links. - Replace the aria-label on poster links with sr-only text, so the anchors carry real anchor text instead of being empty. Text content is also a better accessible name than aria-label. - Give popular and top their own openGraph and twitter tags. They inherited the generic homepage title and description. - Add og:image:alt on movie, tv and person pages. - Add ItemList json-ld to the listing pages. - Drop favorites, watchlist and opengraph-image from the sitemap, and remove the robots.txt disallow that kept crawlers from reading their noindex. - Raise detail revalidate to a week. Cast and release dates barely move, and it cuts regenerations, isr writes and origin transfer sevenfold now that more pages get crawled. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
108 lines
3.2 KiB
TypeScript
108 lines
3.2 KiB
TypeScript
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|
import { Metadata } from 'next';
|
|
import { notFound, permanentRedirect } from 'next/navigation';
|
|
|
|
import JsonLd from '@/components/JsonLd';
|
|
import detailsQuery from '@/data/queries/details';
|
|
import similarQuery from '@/data/queries/similar';
|
|
import { SITE_URL, TITLE } from '@/env';
|
|
import getQueryClient from '@/lib/queryClient';
|
|
import { isMissing, showPath } from '@/lib/utils';
|
|
|
|
import Container from './container';
|
|
|
|
interface Props {
|
|
params: { id: string };
|
|
}
|
|
|
|
export const createShowMetadata =
|
|
(showType: Show['type']) =>
|
|
async ({ params: { id } }: Props): Promise<Metadata> => {
|
|
const queryClient = getQueryClient();
|
|
|
|
const showId = parseInt(id, 10);
|
|
|
|
if (!showId) return notFound();
|
|
|
|
try {
|
|
const { title, overview, poster, backdrop } = await queryClient.fetchQuery(detailsQuery({ showId, showType }));
|
|
|
|
const path = showPath({ type: showType, id: showId, title });
|
|
|
|
return {
|
|
title: `${title} | ${TITLE}`,
|
|
description: overview,
|
|
alternates: { canonical: path },
|
|
openGraph: {
|
|
title,
|
|
description: overview,
|
|
siteName: TITLE,
|
|
images: [{ url: backdrop || poster['2x'], alt: title }],
|
|
type: showType === 'movie' ? 'video.movie' : 'video.tv_show',
|
|
url: path
|
|
}
|
|
};
|
|
} catch (error) {
|
|
if (isMissing(error)) return notFound();
|
|
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const createShowPage = (showType: Show['type']) => {
|
|
const ShowPage = async ({ params: { id } }: Props) => {
|
|
const queryClient = getQueryClient();
|
|
|
|
const showId = parseInt(id, 10);
|
|
|
|
if (!showId) return notFound();
|
|
|
|
const details = await queryClient.fetchQuery(detailsQuery({ showId, showType })).catch((error) => {
|
|
if (isMissing(error)) return null;
|
|
|
|
throw error;
|
|
});
|
|
|
|
if (!details) return notFound();
|
|
|
|
const path = showPath({ type: showType, id: showId, title: details.title });
|
|
|
|
if (decodeURIComponent(`/${showType}/${id}`) !== path) permanentRedirect(path);
|
|
|
|
await queryClient.prefetchQuery(similarQuery({ showId, showType, type: 'similar' }));
|
|
|
|
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}${path}`,
|
|
...(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>
|
|
);
|
|
};
|
|
|
|
return ShowPage;
|
|
};
|