Fix Coming soon
This commit is contained in:
+12
-3
@@ -1,6 +1,7 @@
|
||||
import ar from "@/content/ar";
|
||||
import en from "@/content/en";
|
||||
import type { Dictionary } from "@/content/types";
|
||||
import { isComingSoonMode } from "@/lib/site";
|
||||
|
||||
export const locales = ["ar", "en"] as const;
|
||||
|
||||
@@ -11,18 +12,26 @@ const dictionaries: Record<Locale, Dictionary> = {
|
||||
en,
|
||||
};
|
||||
|
||||
export function getActiveLocale(locale: Locale): Locale {
|
||||
return isComingSoonMode() ? "en" : locale;
|
||||
}
|
||||
|
||||
export function getEnabledLocales(): Locale[] {
|
||||
return isComingSoonMode() ? ["en"] : [...locales];
|
||||
}
|
||||
|
||||
export function isLocale(value: string): value is Locale {
|
||||
return locales.includes(value as Locale);
|
||||
}
|
||||
|
||||
export function getDictionary(locale: Locale): Dictionary {
|
||||
return dictionaries[locale];
|
||||
return dictionaries[getActiveLocale(locale)];
|
||||
}
|
||||
|
||||
export function getDirection(locale: Locale): "rtl" | "ltr" {
|
||||
return locale === "ar" ? "rtl" : "ltr";
|
||||
return getActiveLocale(locale) === "ar" ? "rtl" : "ltr";
|
||||
}
|
||||
|
||||
export function getLocaleName(locale: Locale): string {
|
||||
return locale === "ar" ? "العربية" : "English";
|
||||
return getActiveLocale(locale) === "ar" ? "العربية" : "English";
|
||||
}
|
||||
|
||||
+24
-14
@@ -1,6 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getDictionary, type Locale } from "@/lib/i18n";
|
||||
import { getLocalizedPath, getLocalizedUrl, getModeValue } from "@/lib/site";
|
||||
import { getActiveLocale, getDictionary, type Locale } from "@/lib/i18n";
|
||||
import { getLocalizedPath, getLocalizedUrl, getModeValue, isComingSoonMode } from "@/lib/site";
|
||||
|
||||
type PageKey = "home" | "about" | "contact";
|
||||
|
||||
@@ -11,7 +11,8 @@ const pagePathMap: Record<PageKey, string> = {
|
||||
};
|
||||
|
||||
export function buildPageMetadata(locale: Locale, page: PageKey): Metadata {
|
||||
const dictionary = getDictionary(locale);
|
||||
const activeLocale = getActiveLocale(locale);
|
||||
const dictionary = getDictionary(activeLocale);
|
||||
const pathname = pagePathMap[page];
|
||||
const homeMetadata = getModeValue(dictionary.metadata.home);
|
||||
const metadataByPage = {
|
||||
@@ -30,25 +31,34 @@ export function buildPageMetadata(locale: Locale, page: PageKey): Metadata {
|
||||
} as const;
|
||||
|
||||
const pageMetadata = metadataByPage[page];
|
||||
const canonicalPath = getLocalizedPath(pathname, locale);
|
||||
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: {
|
||||
canonical: canonicalPath,
|
||||
languages: {
|
||||
ar: getLocalizedPath(pathname, "ar"),
|
||||
en: getLocalizedPath(pathname, "en"),
|
||||
"x-default": getLocalizedPath(pathname, "ar"),
|
||||
},
|
||||
},
|
||||
alternates,
|
||||
openGraph: {
|
||||
title: pageMetadata.title,
|
||||
description: pageMetadata.description,
|
||||
url: getLocalizedUrl(pathname, locale),
|
||||
url: isComingSoonMode() && page === "home" ? getLocalizedUrl("/", "en") : getLocalizedUrl(pathname, activeLocale),
|
||||
siteName: dictionary.common.siteTitle,
|
||||
locale: locale === "ar" ? "ar_SA" : "en_US",
|
||||
locale: activeLocale === "ar" ? "ar_SA" : "en_US",
|
||||
type: "website",
|
||||
},
|
||||
twitter: {
|
||||
|
||||
Reference in New Issue
Block a user