feat(seo): slugged show urls, sr-only homepage intro, ISR detail pages
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ce630cd029
commit
735c63471a
11 files changed
+103
-28
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { notFound, permanentRedirect } from 'next/navigation';
|
||||
|
||||
import JsonLd from '@/components/JsonLd';
|
||||
import detailsQuery from '@/data/queries/details';
|
||||
import { SITE_URL, TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
import { showPath } from '@/lib/utils';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
@@ -18,22 +19,26 @@ export const createShowMetadata =
|
||||
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: Number(id), showType })
|
||||
);
|
||||
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: `/${showType}/${id}` },
|
||||
alternates: { canonical: path },
|
||||
openGraph: {
|
||||
title,
|
||||
description: overview,
|
||||
siteName: TITLE,
|
||||
images: [backdrop || poster['2x']],
|
||||
type: showType === 'movie' ? 'video.movie' : 'video.tv_show',
|
||||
url: `/${showType}/${id}`
|
||||
url: path
|
||||
}
|
||||
};
|
||||
} catch (_) {
|
||||
@@ -45,12 +50,18 @@ export const createShowPage = (showType: Show['type']) => {
|
||||
const ShowPage = async ({ params: { id } }: Props) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const showId = Number(id);
|
||||
const showId = parseInt(id, 10);
|
||||
|
||||
if (!showId) return notFound();
|
||||
|
||||
const details = await queryClient.fetchQuery(detailsQuery({ showId, showType })).catch(() => null);
|
||||
|
||||
if (!details) return notFound();
|
||||
|
||||
const path = showPath({ type: showType, id: showId, title: details.title });
|
||||
|
||||
if (decodeURIComponent(`/${showType}/${id}`) !== path) permanentRedirect(path);
|
||||
|
||||
const jsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': showType === 'movie' ? 'Movie' : 'TVSeries',
|
||||
@@ -59,7 +70,7 @@ export const createShowPage = (showType: Show['type']) => {
|
||||
image: details.poster['2x'] || undefined,
|
||||
datePublished: details.release || undefined,
|
||||
genre: details.genres?.map(({ name }) => name),
|
||||
url: `${SITE_URL}/${showType}/${showId}`,
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user