Template
Add page metadata across every route
The root layout exported no metadata, so routes without their own export rendered no title at all, and no route had a description. Add a root metadata block with a title template, Open Graph and Twitter defaults, and fill in the routes that were missing tags. - config/site.ts: description and env-driven absolute url for metadataBase - home, /collections and /shop/collections: titles and descriptions - products/[handle] and collections/[handle]: generateMetadata off the existing catalog fetchers, with canonical and OG image - existing titles: drop the hand-written " — Shop" suffix now that the root template appends it Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011x5jT4fJJCnqPx3umEvXRk
This commit is contained in:
co-authored by
Claude Opus 5
parent
a230187e9f
commit
0263a59c6a
@@ -1,5 +1,47 @@
|
||||
import type { Metadata } from 'next';
|
||||
import ProductDetail from '@/components/shopify/product-detail';
|
||||
import ProductRecommendations from '@/components/shopify/product-recommendations';
|
||||
import { getProduct } from '@/services/shopify/catalog';
|
||||
import { truncate } from '@/lib/utils';
|
||||
import { site } from '@/config/site';
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ handle: string }>;
|
||||
}): Promise<Metadata> {
|
||||
const { handle } = await params;
|
||||
|
||||
// ProductDetail fetches client-side and renders its own empty state, so a
|
||||
// failed lookup here falls back to generic tags rather than a 500.
|
||||
const product = await getProduct(handle).catch(() => null);
|
||||
if (!product) return { title: 'Product' };
|
||||
|
||||
const description = product.description
|
||||
? truncate(product.description, 160)
|
||||
: site.description;
|
||||
const image = product.images.edges[0]?.node;
|
||||
|
||||
return {
|
||||
title: product.title,
|
||||
description,
|
||||
alternates: { canonical: `/products/${product.handle}` },
|
||||
openGraph: {
|
||||
title: product.title,
|
||||
description,
|
||||
url: `/products/${product.handle}`,
|
||||
images: image
|
||||
? [{ url: image.url, alt: image.altText ?? product.title }]
|
||||
: undefined,
|
||||
},
|
||||
twitter: {
|
||||
card: 'summary_large_image',
|
||||
title: product.title,
|
||||
description,
|
||||
images: image ? [image.url] : undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user