-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist category metadata for /[category]/...
- Loading branch information
1 parent
8fb9ddb
commit aae0511
Showing
2 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Metadata> { | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters