Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static params less #34

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scripts/slugify.ts
Original file line number Diff line number Diff line change
@@ -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));
}
6 changes: 6 additions & 0 deletions src/app/(category-sidebar)/[collection]/page.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>;
Expand Down
6 changes: 6 additions & 0 deletions src/app/(category-sidebar)/products/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down
1 change: 1 addition & 0 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down