diff --git a/scripts/slugify.ts b/scripts/slugify.ts new file mode 100644 index 0000000..cb1cf49 --- /dev/null +++ b/scripts/slugify.ts @@ -0,0 +1,12 @@ +import { db } from "../src/db"; +import slugify from "slugify"; +import { collections } from "../src/db/schema"; +import { eq } from "drizzle-orm"; + +const collectionsData = await db.query.collections.findMany(); +for (const collection of collectionsData) { + await db + .update(collections) + .set({ slug: slugify(collection.name, { lower: true }) }) + .where(eq(collections.id, collection.id)); +} diff --git a/src/app/(category-sidebar)/[collection]/page.tsx b/src/app/(category-sidebar)/[collection]/page.tsx index e8413d4..43009b9 100644 --- a/src/app/(category-sidebar)/[collection]/page.tsx +++ b/src/app/(category-sidebar)/[collection]/page.tsx @@ -1,8 +1,14 @@ import { Link } from "@/components/ui/link"; +import { db } from "@/db"; +import { collections } from "@/db/schema"; import { getCollectionDetails } from "@/lib/queries"; import Image from "next/image"; +export async function generateStaticParams() { + return await db.select({ collection: collections.slug }).from(collections); +} + export default async function Home(props: { params: Promise<{ collection: string; diff --git a/src/app/(category-sidebar)/products/[category]/[subcategory]/[product]/page.tsx b/src/app/(category-sidebar)/products/[category]/[subcategory]/[product]/page.tsx index ba68042..553d870 100644 --- a/src/app/(category-sidebar)/products/[category]/[subcategory]/[product]/page.tsx +++ b/src/app/(category-sidebar)/products/[category]/[subcategory]/[product]/page.tsx @@ -5,6 +5,28 @@ import { AddToCartForm } from "@/components/add-to-cart-form"; import { Metadata } from "next"; import { getProductDetails, getProductsForSubcategory } from "@/lib/queries"; +// import { db } from "@/db"; + +// export async function generateStaticParams() { +// const results = await db.query.products.findMany({ +// with: { +// subcategory: { +// with: { +// subcollection: { +// with: { +// category: true, +// }, +// }, +// }, +// }, +// }, +// }); +// return results.map((s) => ({ +// category: s.subcategory.subcollection.category.slug, +// subcategory: s.subcategory.slug, +// product: s.slug, +// })); +// } export async function generateMetadata(props: { params: Promise<{ product: string; category: string; subcategory: string }>; diff --git a/src/app/(category-sidebar)/products/[category]/[subcategory]/page.tsx b/src/app/(category-sidebar)/products/[category]/[subcategory]/page.tsx index 6541424..cbb7596 100644 --- a/src/app/(category-sidebar)/products/[category]/[subcategory]/page.tsx +++ b/src/app/(category-sidebar)/products/[category]/[subcategory]/page.tsx @@ -6,6 +6,23 @@ import { getSubcategory, getSubcategoryProductCount, } from "@/lib/queries"; +// import { db } from "@/db"; + +// export async function generateStaticParams() { +// const results = await db.query.subcategories.findMany({ +// with: { +// subcollection: { +// with: { +// category: true, +// }, +// }, +// }, +// }); +// return results.map((s) => ({ +// category: s.subcollection.category.slug, +// subcategory: s.slug, +// })); +// } export async function generateMetadata(props: { params: Promise<{ category: string; subcategory: string }>; diff --git a/src/app/(category-sidebar)/products/[category]/page.tsx b/src/app/(category-sidebar)/products/[category]/page.tsx index c174203..095b177 100644 --- a/src/app/(category-sidebar)/products/[category]/page.tsx +++ b/src/app/(category-sidebar)/products/[category]/page.tsx @@ -2,6 +2,12 @@ import Image from "next/image"; import { Link } from "@/components/ui/link"; import { notFound } from "next/navigation"; import { getCategory, getCategoryProductCount } from "@/lib/queries"; +import { db } from "@/db"; +import { categories } from "@/db/schema"; + +export async function generateStaticParams() { + return await db.select({ category: categories.slug }).from(categories); +} export default async function Page(props: { params: Promise<{ diff --git a/src/db/schema.ts b/src/db/schema.ts index 97224e8..9d767b6 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -14,6 +14,7 @@ import { relations } from "drizzle-orm"; export const collections = pgTable("collections", { id: serial("id").primaryKey(), name: text("name").notNull(), + slug: text("slug").notNull(), }); export type Collection = typeof collections.$inferSelect;