Polish storefront SEO, specials, and homepage UX.
Publish Meshkee sitemap-config, map product-source specials without variants, restore hero autoplay, and tighten page heroes, product images, and section order. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
11d0ba64ed
commit
24b5649abd
+83
-17
@@ -8,45 +8,108 @@ import { fetchComments } from "@/lib/comments";
|
||||
import { formatPrice } from "@/lib/format";
|
||||
import {
|
||||
brandName,
|
||||
fetchCatalogProductBySlug,
|
||||
fetchCatalogProductByTitle,
|
||||
fetchStoreItemByProduct,
|
||||
fetchStoreVariant,
|
||||
galleryUrls,
|
||||
variantTitle,
|
||||
type CatalogProduct,
|
||||
type StoreVariant,
|
||||
} from "@/lib/store";
|
||||
|
||||
export const revalidate = 60;
|
||||
|
||||
async function resolveProduct(id: string): Promise<{
|
||||
variant: StoreVariant | null;
|
||||
catalog: CatalogProduct | null;
|
||||
productId?: string;
|
||||
}> {
|
||||
const variant = await fetchStoreVariant(id);
|
||||
if (variant) {
|
||||
const catalog = await fetchCatalogProductByTitle(
|
||||
variant.productNameFa || variant.productTitle,
|
||||
variant.productId,
|
||||
);
|
||||
return { variant, catalog, productId: variant.productId };
|
||||
}
|
||||
|
||||
const bySlug = await fetchCatalogProductBySlug(id);
|
||||
if (bySlug) {
|
||||
return { variant: null, catalog: bySlug, productId: bySlug.id };
|
||||
}
|
||||
|
||||
const byProduct = await fetchStoreItemByProduct(id);
|
||||
const firstVariant = byProduct.storeItem?.variants?.[0];
|
||||
if (firstVariant) {
|
||||
const catalog = await fetchCatalogProductByTitle(
|
||||
firstVariant.productNameFa || firstVariant.productTitle,
|
||||
id,
|
||||
);
|
||||
return {
|
||||
variant: {
|
||||
...firstVariant,
|
||||
productId: id,
|
||||
},
|
||||
catalog,
|
||||
productId: id,
|
||||
};
|
||||
}
|
||||
|
||||
return { variant: null, catalog: null };
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const variant = await fetchStoreVariant(id);
|
||||
const resolved = await resolveProduct(id);
|
||||
const title =
|
||||
resolved.catalog?.nameFa ||
|
||||
resolved.catalog?.title ||
|
||||
(resolved.variant ? variantTitle(resolved.variant) : null);
|
||||
const description =
|
||||
resolved.catalog?.summary?.trim() ||
|
||||
stripHtml(resolved.catalog?.descriptionHtml) ||
|
||||
undefined;
|
||||
return {
|
||||
title: variant ? variantTitle(variant) : "محصول",
|
||||
title: title || "محصول",
|
||||
description,
|
||||
};
|
||||
}
|
||||
|
||||
function stripHtml(html?: string | null) {
|
||||
if (!html?.trim()) return undefined;
|
||||
const text = html
|
||||
.replace(/<[^>]+>/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
return text.slice(0, 180) || undefined;
|
||||
}
|
||||
|
||||
export default async function ProductDetailsPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const variant = await fetchStoreVariant(id);
|
||||
if (!variant) notFound();
|
||||
const { variant, catalog, productId } = await resolveProduct(id);
|
||||
if (!variant && !catalog) notFound();
|
||||
|
||||
const [catalog, storeItem, comments] = await Promise.all([
|
||||
fetchCatalogProductByTitle(variant.productNameFa || variant.productTitle, variant.productId),
|
||||
variant.productId ? fetchStoreItemByProduct(variant.productId) : Promise.resolve({ storeItem: undefined }),
|
||||
variant.productId ? fetchComments("product", variant.productId) : Promise.resolve([]),
|
||||
]);
|
||||
const comments = productId ? await fetchComments("product", productId) : [];
|
||||
const sibling =
|
||||
productId && variant
|
||||
? await fetchStoreItemByProduct(productId)
|
||||
: { storeItem: undefined };
|
||||
|
||||
const images = galleryUrls(catalog, variant.productImage);
|
||||
const price = variant.discountedPrice ?? variant.price;
|
||||
const oldPrice = variant.discountedPrice != null ? variant.price : null;
|
||||
const title = catalog?.nameFa || variantTitle(variant);
|
||||
const images = galleryUrls(catalog, variant?.productImage || catalog?.image || catalog?.thumbnailUrl);
|
||||
const price = variant?.discountedPrice ?? variant?.price ?? catalog?.store?.minPrice ?? null;
|
||||
const oldPrice = variant?.discountedPrice != null ? variant.price : null;
|
||||
const title = catalog?.nameFa || catalog?.title || (variant ? variantTitle(variant) : "محصول");
|
||||
const brand = brandName(catalog);
|
||||
const variants = storeItem.storeItem?.variants ?? [];
|
||||
const inStock = variant.stockQuantity == null || variant.stockQuantity > 0;
|
||||
const variants = sibling.storeItem?.variants ?? [];
|
||||
const inStock =
|
||||
variant != null
|
||||
? variant.stockQuantity == null || variant.stockQuantity > 0
|
||||
: catalog?.store?.inStock !== false;
|
||||
|
||||
return (
|
||||
<section className="py-10 sm:py-14">
|
||||
@@ -67,8 +130,11 @@ export default async function ProductDetailsPage({ params }: { params: Promise<{
|
||||
<ProductGallery images={images} alt={title} />
|
||||
<div>
|
||||
{brand ? <p className="text-[13px] font-medium text-brand">{brand}</p> : null}
|
||||
{catalog?.categoryNameFa ? (
|
||||
<p className="mt-1 text-[12px] text-muted">{catalog.categoryNameFa}</p>
|
||||
) : null}
|
||||
<h1 className="mt-2 text-[22px] font-extrabold leading-9 text-ink">{title}</h1>
|
||||
{variant.label && variant.label !== title ? (
|
||||
{variant?.label && variant.label !== title ? (
|
||||
<p className="mt-2 text-[13px] text-muted">{variant.label}</p>
|
||||
) : null}
|
||||
|
||||
@@ -95,7 +161,7 @@ export default async function ProductDetailsPage({ params }: { params: Promise<{
|
||||
<Link
|
||||
key={item.id}
|
||||
href={`/products/${encodeURIComponent(item.id)}`}
|
||||
className={`rounded-lg border px-3 py-1.5 text-[12px] ${item.id === variant.id ? "border-brand bg-paper text-ink" : "border-line bg-white text-muted"}`}
|
||||
className={`rounded-lg border px-3 py-1.5 text-[12px] ${item.id === variant?.id ? "border-brand bg-paper text-ink" : "border-line bg-white text-muted"}`}
|
||||
>
|
||||
{item.label || variantTitle(item)}
|
||||
</Link>
|
||||
|
||||
Reference in New Issue
Block a user