diff --git a/src/app/(category-sidebar)/products/[category]/layout.tsx b/src/app/(category-sidebar)/products/[category]/layout.tsx new file mode 100644 index 0000000..751ad3a --- /dev/null +++ b/src/app/(category-sidebar)/products/[category]/layout.tsx @@ -0,0 +1,45 @@ +import { Metadata } from "next"; +import { db } from "../../../../db"; +import { notFound } from "next/navigation"; + +export async function generateMetadata({ + params, +}: { + params: Promise<{ category: string }>; +}): Promise { + const { category: categoryParam } = await params; + const urlDecoded = decodeURIComponent(categoryParam); + const category = await db.query.categories.findFirst({ + where: (categories, { eq }) => eq(categories.slug, urlDecoded), + with: { + subcollections: true, + }, + orderBy: (categories, { asc }) => asc(categories.name), + }); + + if (!category) { + return notFound(); + } + + const examples = category.subcollections + .slice(0, 2) + .map((s) => s.name) + .join(", ") + .toLowerCase(); + + return { + title: `${category.name}`, + openGraph: { + title: `${category.name}`, + description: `Choose from our selection of ${category.name.toLowerCase()}, including ${examples + (category.subcollections.length > 1 ? "," : "")} and more. In stock and ready to ship.`, + }, + }; +} + +export default function Layout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return children; +} diff --git a/src/app/(category-sidebar)/products/[category]/page.tsx b/src/app/(category-sidebar)/products/[category]/page.tsx index f190f88..f71d240 100644 --- a/src/app/(category-sidebar)/products/[category]/page.tsx +++ b/src/app/(category-sidebar)/products/[category]/page.tsx @@ -6,45 +6,10 @@ import { subcollection, } from "@/db/schema"; import { count, eq } from "drizzle-orm"; -import { Metadata } from "next"; import Image from "next/image"; import Link from "next/link"; import { notFound } from "next/navigation"; -export async function generateMetadata({ - params, -}: { - params: Promise<{ category: string }>; -}): Promise { - const { category: categoryParam } = await params; - const urlDecoded = decodeURIComponent(categoryParam); - const category = await db.query.categories.findFirst({ - where: (categories, { eq }) => eq(categories.slug, urlDecoded), - with: { - subcollections: true, - }, - orderBy: (categories, { asc }) => asc(categories.name), - }); - - if (!category) { - return notFound(); - } - - const examples = category.subcollections - .slice(0, 2) - .map((s) => s.name) - .join(", ") - .toLowerCase(); - - return { - title: `${category.name}`, - openGraph: { - title: `${category.name}`, - description: `Choose from our selection of ${category.name.toLowerCase()}, including ${examples + (category.subcollections.length > 1 ? "," : "")} and more. In stock and ready to ship.`, - }, - }; -} - export default async function Page(props: { params: Promise<{ category: string;