locale upgrade
This commit is contained in:
@@ -32,20 +32,32 @@ export default async function ProjectPage({
|
||||
where: { slug, published: true },
|
||||
include: {
|
||||
translations: {
|
||||
where: { locale },
|
||||
select: { title: true, description: true },
|
||||
select: { title: true, description: true, content: true, locale: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!project) return notFound();
|
||||
|
||||
const tr = project.translations?.[0];
|
||||
const trPreferred = project.translations?.find((t) => t.locale === locale && (t?.title || t?.description));
|
||||
const trDefault = project.translations?.find(
|
||||
(t) => t.locale === project.defaultLocale && (t?.title || t?.description),
|
||||
);
|
||||
const tr = trPreferred ?? trDefault;
|
||||
const { translations: _translations, ...rest } = project;
|
||||
const localizedContent = (() => {
|
||||
if (typeof tr?.content === "string") return tr.content;
|
||||
if (tr?.content && typeof tr.content === "object" && "markdown" in tr.content) {
|
||||
const markdown = (tr.content as Record<string, unknown>).markdown;
|
||||
if (typeof markdown === "string") return markdown;
|
||||
}
|
||||
return project.content;
|
||||
})();
|
||||
const localized = {
|
||||
...rest,
|
||||
title: tr?.title ?? project.title,
|
||||
description: tr?.description ?? project.description,
|
||||
content: localizedContent,
|
||||
};
|
||||
|
||||
return <ProjectDetailClient project={localized} locale={locale} />;
|
||||
|
||||
Reference in New Issue
Block a user