71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { getActiveLocale, getDictionary, type Locale } from "@/lib/i18n";
|
|
import { getLocalizedPath, getLocalizedUrl, getModeValue, isComingSoonMode } from "@/lib/site";
|
|
|
|
type PageKey = "home" | "about" | "contact";
|
|
|
|
const pagePathMap: Record<PageKey, string> = {
|
|
home: "",
|
|
about: "/about",
|
|
contact: "/contact",
|
|
};
|
|
|
|
export function buildPageMetadata(locale: Locale, page: PageKey): Metadata {
|
|
const activeLocale = getActiveLocale(locale);
|
|
const dictionary = getDictionary(activeLocale);
|
|
const pathname = pagePathMap[page];
|
|
const homeMetadata = getModeValue(dictionary.metadata.home);
|
|
const metadataByPage = {
|
|
home: {
|
|
title: homeMetadata.title,
|
|
description: homeMetadata.description,
|
|
},
|
|
about: {
|
|
title: dictionary.metadata.aboutTitle,
|
|
description: dictionary.metadata.aboutDescription,
|
|
},
|
|
contact: {
|
|
title: dictionary.metadata.contactTitle,
|
|
description: dictionary.metadata.contactDescription,
|
|
},
|
|
} as const;
|
|
|
|
const pageMetadata = metadataByPage[page];
|
|
const canonicalPath = isComingSoonMode() && page === "home" ? "/" : getLocalizedPath(pathname, activeLocale);
|
|
const alternates = isComingSoonMode()
|
|
? {
|
|
canonical: canonicalPath,
|
|
languages: {
|
|
en: "/",
|
|
"x-default": "/",
|
|
},
|
|
}
|
|
: {
|
|
canonical: canonicalPath,
|
|
languages: {
|
|
ar: getLocalizedPath(pathname, "ar"),
|
|
en: getLocalizedPath(pathname, "en"),
|
|
"x-default": getLocalizedPath(pathname, "ar"),
|
|
},
|
|
};
|
|
|
|
return {
|
|
title: pageMetadata.title,
|
|
description: pageMetadata.description,
|
|
alternates,
|
|
openGraph: {
|
|
title: pageMetadata.title,
|
|
description: pageMetadata.description,
|
|
url: isComingSoonMode() && page === "home" ? getLocalizedUrl("/", "en") : getLocalizedUrl(pathname, activeLocale),
|
|
siteName: dictionary.common.siteTitle,
|
|
locale: activeLocale === "ar" ? "ar_SA" : "en_US",
|
|
type: "website",
|
|
},
|
|
twitter: {
|
|
card: "summary_large_image",
|
|
title: pageMetadata.title,
|
|
description: pageMetadata.description,
|
|
},
|
|
};
|
|
}
|