REFACTORED - Flatten portfolio category routes to /portfolio/[slug]
Merge the category and project routes under a single /portfolio/[slug] segment via resolvePortfolioSlug (category wins over project on a slug clash). Removes the /portfolio/category/... prefix from links, redirect, and sitemap. Adds resolver integration tests.
This commit is contained in:
@@ -4,16 +4,20 @@ import { notFound } from "next/navigation";
|
||||
|
||||
import { Container } from "@/components/layout/container";
|
||||
import { PageHero } from "@/components/layout/page-hero";
|
||||
import { PortfolioCategoryFilter } from "@/components/site/portfolio-category-filter";
|
||||
import { PortfolioProjectDetail } from "@/components/site/portfolio-project-detail";
|
||||
import { PortfolioProjectGrid } from "@/components/site/portfolio-project-grid";
|
||||
import { getSiteSettings } from "@/lib/app-config";
|
||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||
import { resolveLocale } from "@/lib/locale";
|
||||
import {
|
||||
getActivePortfolioCategories,
|
||||
getLocalizedValue,
|
||||
getPublishedPortfolioProjectBySlug,
|
||||
getPublishedPortfolioProjects,
|
||||
resolvePortfolioSlug,
|
||||
} from "@/lib/portfolio";
|
||||
|
||||
type PortfolioItemPageProps = {
|
||||
type PortfolioSlugPageProps = {
|
||||
params: Promise<{
|
||||
locale: string;
|
||||
slug: string;
|
||||
@@ -22,41 +26,88 @@ type PortfolioItemPageProps = {
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function generateMetadata({ params }: PortfolioItemPageProps): Promise<Metadata> {
|
||||
export async function generateMetadata({ params }: PortfolioSlugPageProps): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const siteSettings = await getSiteSettings();
|
||||
const localeKey = resolveLocale(await getLocale().catch(() => siteSettings.defaultLocale), siteSettings.defaultLocale);
|
||||
const item = await getPublishedPortfolioProjectBySlug(slug);
|
||||
const resolved = await resolvePortfolioSlug(slug);
|
||||
|
||||
if (!item) {
|
||||
if (!resolved) {
|
||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
||||
return await buildLocalizedMetadata({
|
||||
locale: localeKey,
|
||||
pathname: `/portfolio/${slug}`,
|
||||
title: "Portfolio",
|
||||
description: "Portfolio item",
|
||||
title: t("title"),
|
||||
description: t("intro"),
|
||||
});
|
||||
}
|
||||
|
||||
if (resolved.kind === "category") {
|
||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
||||
return await buildLocalizedMetadata({
|
||||
locale: localeKey,
|
||||
pathname: `/portfolio/${slug}`,
|
||||
title: getLocalizedValue(resolved.category.name, localeKey),
|
||||
description: getLocalizedValue(resolved.category.description, localeKey) || t("intro"),
|
||||
});
|
||||
}
|
||||
|
||||
return await buildLocalizedMetadata({
|
||||
locale: localeKey,
|
||||
pathname: `/portfolio/${slug}`,
|
||||
title: getLocalizedValue(item.title, localeKey),
|
||||
description: getLocalizedValue(item.summary, localeKey),
|
||||
title: getLocalizedValue(resolved.project.title, localeKey),
|
||||
description: getLocalizedValue(resolved.project.summary, localeKey),
|
||||
});
|
||||
}
|
||||
|
||||
export default async function PortfolioItemPage({
|
||||
params,
|
||||
}: PortfolioItemPageProps) {
|
||||
export default async function PortfolioSlugPage({ params }: PortfolioSlugPageProps) {
|
||||
const { slug } = await params;
|
||||
const siteSettings = await getSiteSettings();
|
||||
const localeKey = resolveLocale(await getLocale().catch(() => siteSettings.defaultLocale), siteSettings.defaultLocale);
|
||||
const item = await getPublishedPortfolioProjectBySlug(slug);
|
||||
const resolved = await resolvePortfolioSlug(slug);
|
||||
|
||||
if (!item) {
|
||||
if (!resolved) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
if (resolved.kind === "category") {
|
||||
const { category } = resolved;
|
||||
const [categories, projects] = await Promise.all([
|
||||
getActivePortfolioCategories(),
|
||||
getPublishedPortfolioProjects({ categorySlug: slug }),
|
||||
]);
|
||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHero
|
||||
locale={localeKey}
|
||||
badge={t("heroBadge")}
|
||||
title={getLocalizedValue(category.name, localeKey)}
|
||||
description={getLocalizedValue(category.description, localeKey) || t("intro")}
|
||||
/>
|
||||
|
||||
<Container className="flex flex-col gap-section pb-12 lg:pb-16">
|
||||
<PortfolioCategoryFilter
|
||||
locale={localeKey}
|
||||
defaultLocale={siteSettings.defaultLocale}
|
||||
categories={categories}
|
||||
allLabel={t("all")}
|
||||
activeCategorySlug={category.slug}
|
||||
/>
|
||||
<PortfolioProjectGrid
|
||||
locale={localeKey}
|
||||
defaultLocale={siteSettings.defaultLocale}
|
||||
projects={projects}
|
||||
emptyLabel={t("empty")}
|
||||
openLabel={t("open")}
|
||||
/>
|
||||
</Container>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const { project: item } = resolved;
|
||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioDetail" });
|
||||
const title = getLocalizedValue(item.title, localeKey);
|
||||
const category = getLocalizedValue(item.category.name, localeKey);
|
||||
|
||||
Reference in New Issue
Block a user