Files
sass-mohfarawati/app/[locale]/(site)/portfolio/[slug]/page.tsx
T
MOH c18128c965
CI / quality (push) Waiting to run
Fix runtime default locale resolution
2026-03-15 06:02:27 +01:00

81 lines
2.2 KiB
TypeScript

import type { Metadata } from "next";
import { getTranslations } from "next-intl/server";
import { notFound } from "next/navigation";
import { Container } from "@/components/layout/container";
import { PageHero } from "@/components/layout/page-hero";
import { PortfolioProjectDetail } from "@/components/site/portfolio-project-detail";
import { getSiteSettings } from "@/lib/app-config";
import { buildLocalizedMetadata } from "@/lib/metadata";
import { FALLBACK_LOCALE, resolveLocale } from "@/lib/locale";
import {
getLocalizedValue,
getPublishedPortfolioProjectBySlug,
} from "@/lib/portfolio";
type PortfolioItemPageProps = {
params: Promise<{
locale: string;
slug: string;
}>;
};
export const dynamic = "force-dynamic";
export async function generateMetadata({ params }: PortfolioItemPageProps): Promise<Metadata> {
const { locale, slug } = await params;
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
const item = await getPublishedPortfolioProjectBySlug(slug);
if (!item) {
return await buildLocalizedMetadata({
locale: localeKey,
pathname: `/portfolio/${slug}`,
title: "Portfolio",
description: "Portfolio item",
});
}
return await buildLocalizedMetadata({
locale: localeKey,
pathname: `/portfolio/${slug}`,
title: getLocalizedValue(item.title, localeKey),
description: getLocalizedValue(item.summary, localeKey),
});
}
export default async function PortfolioItemPage({
params,
}: PortfolioItemPageProps) {
const { locale, slug } = await params;
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
const item = await getPublishedPortfolioProjectBySlug(slug);
if (!item) {
notFound();
}
const [t, siteSettings] = await Promise.all([
getTranslations({ locale: localeKey, namespace: "portfolioDetail" }),
getSiteSettings(),
]);
return (
<>
<PageHero
title={getLocalizedValue(item.title, localeKey)}
description={getLocalizedValue(item.summary, localeKey)}
/>
<Container size="wide" className="pb-12 lg:pb-16">
<PortfolioProjectDetail
item={item}
locale={localeKey}
defaultLocale={siteSettings.defaultLocale}
t={t}
/>
</Container>
</>
);
}