Skip to content
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
58 changes: 34 additions & 24 deletions app/[locale]/apps/categories/[catetgoryName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ const Page = async (props: {
<BreadcrumbItem>
<BreadcrumbLink href="/">Ethereum.org</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator className="me-[0.625rem] ms-[0.625rem] text-gray-400">
<BreadcrumbSeparator className="ms-[0.625rem] me-[0.625rem] text-gray-400">
/
</BreadcrumbSeparator>
<BreadcrumbItem>
<BreadcrumbLink href="/apps" className="uppercase">
{t("page-apps-all-apps")}
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator className="me-[0.625rem] ms-[0.625rem] text-gray-400">
<BreadcrumbSeparator className="ms-[0.625rem] me-[0.625rem] text-gray-400">
/
</BreadcrumbSeparator>
<BreadcrumbItem>
Expand Down Expand Up @@ -223,35 +223,45 @@ export async function generateMetadata(props: {
}) {
const params = await props.params
const { locale, catetgoryName } = params
const t = await getTranslations("page-apps")

// Normalize slug to lowercase
const normalizedSlug = catetgoryName.toLowerCase()
try {
const t = await getTranslations("page-apps")

// Find category by matching the slug
const categoryEntry = Object.entries(appsCategories).find(
([, categoryData]) => categoryData.slug === normalizedSlug
)
// Normalize slug to lowercase
const normalizedSlug = catetgoryName.toLowerCase()

if (!categoryEntry) {
notFound()
}
// Find category by matching the slug
const categoryEntry = Object.entries(appsCategories).find(
([, categoryData]) => categoryData.slug === normalizedSlug
)

const [categoryEnum, category] = categoryEntry
if (!categoryEntry) {
throw new Error(`App category not found: ${catetgoryName}`)
}

if (!isValidCategory(categoryEnum)) {
notFound()
}
const [categoryEnum, category] = categoryEntry

const title = t(category.metaTitle)
const description = t(category.metaDescription)
if (!isValidCategory(categoryEnum)) {
throw new Error(`Invalid app category enum: ${categoryEnum}`)
}

return await getMetadata({
locale,
slug: ["apps", "categories", normalizedSlug],
title,
description,
})
const title = t(category.metaTitle)
const description = t(category.metaDescription)

return await getMetadata({
locale,
slug: ["apps", "categories", normalizedSlug],
title,
description,
})
} catch {
const t = await getTranslations("common")

return {
title: t("page-not-found"),
description: t("page-not-found-description"),
}
}
}

export default Page
37 changes: 23 additions & 14 deletions app/[locale]/developers/tools/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const Page = async (props: {

<Section id="categories" className="space-y-4">
<h2>{t("page-developers-tools-categories-title-other")}</h2>
<div className="grid grid-cols-fill-4 gap-8">
<div className="grid-cols-fill-4 grid gap-8">
{DEV_TOOL_CATEGORIES.filter(({ slug }) => slug !== category).map(
({ slug, Icon }) => (
<SubpageCard
Expand Down Expand Up @@ -152,20 +152,29 @@ export async function generateMetadata(props: {
const params = await props.params
const { locale, category } = params

if (!VALID_CATEGORY_SLUGS.has(category as DeveloperToolCategorySlug)) {
notFound()
try {
if (!VALID_CATEGORY_SLUGS.has(category as DeveloperToolCategorySlug)) {
throw new Error(`Invalid developer tools category: ${category}`)
}

const t = await getTranslations("page-developers-tools")

return await getMetadata({
locale,
slug: ["developers", "tools", category],
title: t(`page-developers-tools-category-${category}-title`),
description: t(
`page-developers-tools-category-${category}-meta-description`
),
})
} catch {
const t = await getTranslations("common")

return {
title: t("page-not-found"),
description: t("page-not-found-description"),
}
}

const t = await getTranslations("page-developers-tools")

return await getMetadata({
locale,
slug: ["developers", "tools", category],
title: t(`page-developers-tools-category-${category}-title`),
description: t(
`page-developers-tools-category-${category}-meta-description`
),
})
}

export default Page
Loading