This commit is contained in:
@@ -4,7 +4,7 @@ import { getTranslations } from "next-intl/server";
|
|||||||
import { Container } from "@/components/layout/container";
|
import { Container } from "@/components/layout/container";
|
||||||
import { PageHero } from "@/components/layout/page-hero";
|
import { PageHero } from "@/components/layout/page-hero";
|
||||||
import { AppCard } from "@/components/ui/app-card";
|
import { AppCard } from "@/components/ui/app-card";
|
||||||
import { resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, resolveLocale } from "@/lib/locale";
|
||||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||||
|
|
||||||
type AboutPageProps = {
|
type AboutPageProps = {
|
||||||
@@ -17,7 +17,7 @@ export const dynamic = "force-dynamic";
|
|||||||
|
|
||||||
export async function generateMetadata({ params }: AboutPageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: AboutPageProps): Promise<Metadata> {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "aboutPage" });
|
const t = await getTranslations({ locale: localeKey, namespace: "aboutPage" });
|
||||||
|
|
||||||
return await buildLocalizedMetadata({
|
return await buildLocalizedMetadata({
|
||||||
@@ -30,7 +30,7 @@ export async function generateMetadata({ params }: AboutPageProps): Promise<Meta
|
|||||||
|
|
||||||
export default async function AboutPage({ params }: AboutPageProps) {
|
export default async function AboutPage({ params }: AboutPageProps) {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "aboutPage" });
|
const t = await getTranslations({ locale: localeKey, namespace: "aboutPage" });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ function getStringValue(formData: FormData, key: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function submitContactFormAction(formData: FormData) {
|
export async function submitContactFormAction(formData: FormData) {
|
||||||
const locale = resolveLocale(String(formData.get("locale") ?? ""));
|
|
||||||
const siteSettings = await getSiteSettings();
|
const siteSettings = await getSiteSettings();
|
||||||
|
const locale = resolveLocale(String(formData.get("locale") ?? ""), siteSettings.defaultLocale);
|
||||||
const contactPath = getLocalizedPath(locale, "/contact", siteSettings.defaultLocale);
|
const contactPath = getLocalizedPath(locale, "/contact", siteSettings.defaultLocale);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { MotionFade } from "@/components/motion-fade";
|
|||||||
import { ContactForm } from "@/components/site/contact-form";
|
import { ContactForm } from "@/components/site/contact-form";
|
||||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||||
import { getPublicContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
|
import { getPublicContactProtectionSettings, getSiteSettings } from "@/lib/app-config";
|
||||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||||
import { AppCard } from "@/components/ui/app-card";
|
import { AppCard } from "@/components/ui/app-card";
|
||||||
import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ type ContactPageProps = {
|
|||||||
|
|
||||||
export async function generateMetadata({ params }: ContactPageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: ContactPageProps): Promise<Metadata> {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "contactPage" });
|
const t = await getTranslations({ locale: localeKey, namespace: "contactPage" });
|
||||||
|
|
||||||
return await buildLocalizedMetadata({
|
return await buildLocalizedMetadata({
|
||||||
@@ -35,7 +35,7 @@ export async function generateMetadata({ params }: ContactPageProps): Promise<Me
|
|||||||
|
|
||||||
export default async function ContactPage({ params }: ContactPageProps) {
|
export default async function ContactPage({ params }: ContactPageProps) {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const [t, protection, siteSettings] = await Promise.all([
|
const [t, protection, siteSettings] = await Promise.all([
|
||||||
getTranslations({ locale: localeKey, namespace: "contactPage" }),
|
getTranslations({ locale: localeKey, namespace: "contactPage" }),
|
||||||
getPublicContactProtectionSettings(),
|
getPublicContactProtectionSettings(),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { SiteFooter } from "@/components/layout/site-footer";
|
|||||||
import { SiteHeader } from "@/components/layout/site-header";
|
import { SiteHeader } from "@/components/layout/site-header";
|
||||||
import { isAdminAuthenticated } from "@/lib/admin-auth";
|
import { isAdminAuthenticated } from "@/lib/admin-auth";
|
||||||
import { getMaintenanceMode, getSiteSettings, getSiteSettingsMediaBindings } from "@/lib/app-config";
|
import { getMaintenanceMode, getSiteSettings, getSiteSettingsMediaBindings } from "@/lib/app-config";
|
||||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||||
|
|
||||||
type SiteLayoutProps = {
|
type SiteLayoutProps = {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -23,7 +23,7 @@ export default async function SiteLayout({ children, params }: SiteLayoutProps)
|
|||||||
noStore();
|
noStore();
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
|
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const [maintenanceEnabled, mediaBindings, siteSettings] = await Promise.all([
|
const [maintenanceEnabled, mediaBindings, siteSettings] = await Promise.all([
|
||||||
getMaintenanceMode(),
|
getMaintenanceMode(),
|
||||||
getSiteSettingsMediaBindings(),
|
getSiteSettingsMediaBindings(),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import { buildLocalizedMetadata } from "@/lib/metadata";
|
|||||||
import { AppCard } from "@/components/ui/app-card";
|
import { AppCard } from "@/components/ui/app-card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CardContent } from "@/components/ui/card";
|
import { CardContent } from "@/components/ui/card";
|
||||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||||
|
|
||||||
type HomePageProps = {
|
type HomePageProps = {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
@@ -43,7 +43,7 @@ export const dynamic = "force-dynamic";
|
|||||||
|
|
||||||
export async function generateMetadata({ params }: HomePageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: HomePageProps): Promise<Metadata> {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const [t, siteSettings] = await Promise.all([
|
const [t, siteSettings] = await Promise.all([
|
||||||
getTranslations({ locale: localeKey, namespace: "homepage" }),
|
getTranslations({ locale: localeKey, namespace: "homepage" }),
|
||||||
getSiteSettings(),
|
getSiteSettings(),
|
||||||
@@ -60,7 +60,7 @@ export async function generateMetadata({ params }: HomePageProps): Promise<Metad
|
|||||||
|
|
||||||
export default async function HomePage({ params }: HomePageProps) {
|
export default async function HomePage({ params }: HomePageProps) {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const [t, marqueeSettings, siteSettings] = await Promise.all([
|
const [t, marqueeSettings, siteSettings] = await Promise.all([
|
||||||
getTranslations({ locale: localeKey, namespace: "homepage" }),
|
getTranslations({ locale: localeKey, namespace: "homepage" }),
|
||||||
getMarqueeSettings(),
|
getMarqueeSettings(),
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import { notFound } from "next/navigation";
|
|||||||
import { Container } from "@/components/layout/container";
|
import { Container } from "@/components/layout/container";
|
||||||
import { PageHero } from "@/components/layout/page-hero";
|
import { PageHero } from "@/components/layout/page-hero";
|
||||||
import { PortfolioProjectDetail } from "@/components/site/portfolio-project-detail";
|
import { PortfolioProjectDetail } from "@/components/site/portfolio-project-detail";
|
||||||
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||||
import { resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, resolveLocale } from "@/lib/locale";
|
||||||
import {
|
import {
|
||||||
getLocalizedValue,
|
getLocalizedValue,
|
||||||
getPublishedPortfolioProjectBySlug,
|
getPublishedPortfolioProjectBySlug,
|
||||||
@@ -23,7 +24,7 @@ export const dynamic = "force-dynamic";
|
|||||||
|
|
||||||
export async function generateMetadata({ params }: PortfolioItemPageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: PortfolioItemPageProps): Promise<Metadata> {
|
||||||
const { locale, slug } = await params;
|
const { locale, slug } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const item = await getPublishedPortfolioProjectBySlug(slug);
|
const item = await getPublishedPortfolioProjectBySlug(slug);
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
@@ -47,14 +48,17 @@ export default async function PortfolioItemPage({
|
|||||||
params,
|
params,
|
||||||
}: PortfolioItemPageProps) {
|
}: PortfolioItemPageProps) {
|
||||||
const { locale, slug } = await params;
|
const { locale, slug } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const item = await getPublishedPortfolioProjectBySlug(slug);
|
const item = await getPublishedPortfolioProjectBySlug(slug);
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioDetail" });
|
const [t, siteSettings] = await Promise.all([
|
||||||
|
getTranslations({ locale: localeKey, namespace: "portfolioDetail" }),
|
||||||
|
getSiteSettings(),
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -64,7 +68,12 @@ export default async function PortfolioItemPage({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Container size="wide" className="pb-12 lg:pb-16">
|
<Container size="wide" className="pb-12 lg:pb-16">
|
||||||
<PortfolioProjectDetail item={item} locale={localeKey} t={t} />
|
<PortfolioProjectDetail
|
||||||
|
item={item}
|
||||||
|
locale={localeKey}
|
||||||
|
defaultLocale={siteSettings.defaultLocale}
|
||||||
|
t={t}
|
||||||
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import { Container } from "@/components/layout/container";
|
|||||||
import { PageHero } from "@/components/layout/page-hero";
|
import { PageHero } from "@/components/layout/page-hero";
|
||||||
import { PortfolioCategoryFilter } from "@/components/site/portfolio-category-filter";
|
import { PortfolioCategoryFilter } from "@/components/site/portfolio-category-filter";
|
||||||
import { PortfolioProjectGrid } from "@/components/site/portfolio-project-grid";
|
import { PortfolioProjectGrid } from "@/components/site/portfolio-project-grid";
|
||||||
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||||
import { resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, resolveLocale } from "@/lib/locale";
|
||||||
import {
|
import {
|
||||||
getActivePortfolioCategories,
|
getActivePortfolioCategories,
|
||||||
getActivePortfolioCategoryBySlug,
|
getActivePortfolioCategoryBySlug,
|
||||||
@@ -26,7 +27,7 @@ export const dynamic = "force-dynamic";
|
|||||||
|
|
||||||
export async function generateMetadata({ params }: PortfolioCategoryPageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: PortfolioCategoryPageProps): Promise<Metadata> {
|
||||||
const { locale, slug } = await params;
|
const { locale, slug } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
||||||
const category = await getActivePortfolioCategoryBySlug(slug);
|
const category = await getActivePortfolioCategoryBySlug(slug);
|
||||||
|
|
||||||
@@ -51,9 +52,10 @@ export default async function PortfolioCategoryPage({
|
|||||||
params,
|
params,
|
||||||
}: PortfolioCategoryPageProps) {
|
}: PortfolioCategoryPageProps) {
|
||||||
const { locale, slug } = await params;
|
const { locale, slug } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
const [t, siteSettings, categories, category, projects] = await Promise.all([
|
||||||
const [categories, category, projects] = await Promise.all([
|
getTranslations({ locale: localeKey, namespace: "portfolioPage" }),
|
||||||
|
getSiteSettings(),
|
||||||
getActivePortfolioCategories(),
|
getActivePortfolioCategories(),
|
||||||
getActivePortfolioCategoryBySlug(slug),
|
getActivePortfolioCategoryBySlug(slug),
|
||||||
getPublishedPortfolioProjects({ categorySlug: slug }),
|
getPublishedPortfolioProjects({ categorySlug: slug }),
|
||||||
@@ -75,12 +77,14 @@ export default async function PortfolioCategoryPage({
|
|||||||
<Container className="flex flex-col gap-section pb-12 lg:pb-16">
|
<Container className="flex flex-col gap-section pb-12 lg:pb-16">
|
||||||
<PortfolioCategoryFilter
|
<PortfolioCategoryFilter
|
||||||
locale={localeKey}
|
locale={localeKey}
|
||||||
|
defaultLocale={siteSettings.defaultLocale}
|
||||||
categories={categories}
|
categories={categories}
|
||||||
allLabel={t("all")}
|
allLabel={t("all")}
|
||||||
activeCategorySlug={category.slug}
|
activeCategorySlug={category.slug}
|
||||||
/>
|
/>
|
||||||
<PortfolioProjectGrid
|
<PortfolioProjectGrid
|
||||||
locale={localeKey}
|
locale={localeKey}
|
||||||
|
defaultLocale={siteSettings.defaultLocale}
|
||||||
projects={projects}
|
projects={projects}
|
||||||
emptyLabel={t("empty")}
|
emptyLabel={t("empty")}
|
||||||
openLabel={t("open")}
|
openLabel={t("open")}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { permanentRedirect } from "next/navigation";
|
import { permanentRedirect } from "next/navigation";
|
||||||
|
|
||||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
|
import { FALLBACK_LOCALE, getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||||
|
|
||||||
type PortfolioCategoryIndexPageProps = {
|
type PortfolioCategoryIndexPageProps = {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
@@ -12,7 +13,8 @@ export default async function PortfolioCategoryIndexPage({
|
|||||||
params,
|
params,
|
||||||
}: PortfolioCategoryIndexPageProps) {
|
}: PortfolioCategoryIndexPageProps) {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
permanentRedirect(getLocalizedPath(localeKey, "/portfolio"));
|
permanentRedirect(getLocalizedPath(localeKey, "/portfolio", siteSettings.defaultLocale));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import { Container } from "@/components/layout/container";
|
|||||||
import { PageHero } from "@/components/layout/page-hero";
|
import { PageHero } from "@/components/layout/page-hero";
|
||||||
import { PortfolioCategoryFilter } from "@/components/site/portfolio-category-filter";
|
import { PortfolioCategoryFilter } from "@/components/site/portfolio-category-filter";
|
||||||
import { PortfolioProjectGrid } from "@/components/site/portfolio-project-grid";
|
import { PortfolioProjectGrid } from "@/components/site/portfolio-project-grid";
|
||||||
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||||
import { getActivePortfolioCategories, getPublishedPortfolioProjects } from "@/lib/portfolio";
|
import { getActivePortfolioCategories, getPublishedPortfolioProjects } from "@/lib/portfolio";
|
||||||
|
|
||||||
type PortfolioPageProps = {
|
type PortfolioPageProps = {
|
||||||
@@ -23,7 +24,7 @@ export const dynamic = "force-dynamic";
|
|||||||
|
|
||||||
export async function generateMetadata({ params }: PortfolioPageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: PortfolioPageProps): Promise<Metadata> {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
||||||
|
|
||||||
return await buildLocalizedMetadata({
|
return await buildLocalizedMetadata({
|
||||||
@@ -42,12 +43,15 @@ export default async function PortfolioPage({
|
|||||||
params,
|
params,
|
||||||
searchParams,
|
searchParams,
|
||||||
]);
|
]);
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "portfolioPage" });
|
const [t, siteSettings] = await Promise.all([
|
||||||
|
getTranslations({ locale: localeKey, namespace: "portfolioPage" }),
|
||||||
|
getSiteSettings(),
|
||||||
|
]);
|
||||||
const selectedCategory = resolvedSearchParams?.category ?? "";
|
const selectedCategory = resolvedSearchParams?.category ?? "";
|
||||||
|
|
||||||
if (selectedCategory) {
|
if (selectedCategory) {
|
||||||
redirect(getLocalizedPath(localeKey, `/portfolio/category/${selectedCategory}`));
|
redirect(getLocalizedPath(localeKey, `/portfolio/category/${selectedCategory}`, siteSettings.defaultLocale));
|
||||||
}
|
}
|
||||||
|
|
||||||
const [categories, projects] = await Promise.all([
|
const [categories, projects] = await Promise.all([
|
||||||
@@ -65,9 +69,15 @@ export default async function PortfolioPage({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Container className="flex flex-col gap-section pb-12 lg:pb-16">
|
<Container className="flex flex-col gap-section pb-12 lg:pb-16">
|
||||||
<PortfolioCategoryFilter locale={localeKey} categories={categories} allLabel={t("all")} />
|
<PortfolioCategoryFilter
|
||||||
|
locale={localeKey}
|
||||||
|
defaultLocale={siteSettings.defaultLocale}
|
||||||
|
categories={categories}
|
||||||
|
allLabel={t("all")}
|
||||||
|
/>
|
||||||
<PortfolioProjectGrid
|
<PortfolioProjectGrid
|
||||||
locale={localeKey}
|
locale={localeKey}
|
||||||
|
defaultLocale={siteSettings.defaultLocale}
|
||||||
projects={projects}
|
projects={projects}
|
||||||
emptyLabel={t("empty")}
|
emptyLabel={t("empty")}
|
||||||
openLabel={t("open")}
|
openLabel={t("open")}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { MotionFade } from "@/components/motion-fade";
|
|||||||
import { HeroShell, HeroTitle } from "@/components/layout/site-hero";
|
import { HeroShell, HeroTitle } from "@/components/layout/site-hero";
|
||||||
import { getSiteSettings } from "@/lib/app-config";
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||||
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, getLocalizedPath, resolveLocale } from "@/lib/locale";
|
||||||
import { AppCard } from "@/components/ui/app-card";
|
import { AppCard } from "@/components/ui/app-card";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CardContent } from "@/components/ui/card";
|
import { CardContent } from "@/components/ui/card";
|
||||||
@@ -21,7 +21,7 @@ type SuccessPageProps = {
|
|||||||
|
|
||||||
export async function generateMetadata({ params }: SuccessPageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: SuccessPageProps): Promise<Metadata> {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "successPage" });
|
const t = await getTranslations({ locale: localeKey, namespace: "successPage" });
|
||||||
|
|
||||||
return await buildLocalizedMetadata({
|
return await buildLocalizedMetadata({
|
||||||
@@ -34,7 +34,7 @@ export async function generateMetadata({ params }: SuccessPageProps): Promise<Me
|
|||||||
|
|
||||||
export default async function SuccessPage({ params }: SuccessPageProps) {
|
export default async function SuccessPage({ params }: SuccessPageProps) {
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const [t, siteSettings] = await Promise.all([
|
const [t, siteSettings] = await Promise.all([
|
||||||
getTranslations({ locale: localeKey, namespace: "successPage" }),
|
getTranslations({ locale: localeKey, namespace: "successPage" }),
|
||||||
getSiteSettings(),
|
getSiteSettings(),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { MotionFade } from "@/components/motion-fade";
|
|||||||
import { HeroShell, HeroTitle } from "@/components/layout/site-hero";
|
import { HeroShell, HeroTitle } from "@/components/layout/site-hero";
|
||||||
import { getSiteSettings } from "@/lib/app-config";
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import { buildLocalizedMetadata } from "@/lib/metadata";
|
import { buildLocalizedMetadata } from "@/lib/metadata";
|
||||||
import { resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, resolveLocale } from "@/lib/locale";
|
||||||
|
|
||||||
type ComingSoonPageProps = {
|
type ComingSoonPageProps = {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
@@ -22,7 +22,7 @@ export const revalidate = 0;
|
|||||||
export async function generateMetadata({ params }: ComingSoonPageProps): Promise<Metadata> {
|
export async function generateMetadata({ params }: ComingSoonPageProps): Promise<Metadata> {
|
||||||
noStore();
|
noStore();
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const t = await getTranslations({ locale: localeKey, namespace: "comingSoon" });
|
const t = await getTranslations({ locale: localeKey, namespace: "comingSoon" });
|
||||||
const siteSettings = await getSiteSettings();
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ export default async function ComingSoonPage({
|
|||||||
}: ComingSoonPageProps) {
|
}: ComingSoonPageProps) {
|
||||||
noStore();
|
noStore();
|
||||||
const { locale } = await params;
|
const { locale } = await params;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, FALLBACK_LOCALE);
|
||||||
const [t, siteSettings] = await Promise.all([
|
const [t, siteSettings] = await Promise.all([
|
||||||
getTranslations({ locale: localeKey, namespace: "comingSoon" }),
|
getTranslations({ locale: localeKey, namespace: "comingSoon" }),
|
||||||
getSiteSettings(),
|
getSiteSettings(),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { routing } from "@/i18n/routing";
|
|||||||
import { getAdminAppPath, toInternalAdminPath } from "@/lib/admin-routing";
|
import { getAdminAppPath, toInternalAdminPath } from "@/lib/admin-routing";
|
||||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||||
import { getLocalizedPath } from "@/lib/locale";
|
import { getLocalizedPath } from "@/lib/locale";
|
||||||
import { setMaintenanceMode } from "@/lib/app-config";
|
import { getSiteSettings, setMaintenanceMode } from "@/lib/app-config";
|
||||||
|
|
||||||
async function ensureAdmin() {
|
async function ensureAdmin() {
|
||||||
if (!(await isAdminAuthenticated())) {
|
if (!(await isAdminAuthenticated())) {
|
||||||
@@ -33,10 +33,11 @@ export async function updateMaintenanceModeAction(formData: FormData) {
|
|||||||
revalidatePath(toInternalAdminPath("/"));
|
revalidatePath(toInternalAdminPath("/"));
|
||||||
revalidatePath(toInternalAdminPath("/maintenance"));
|
revalidatePath(toInternalAdminPath("/maintenance"));
|
||||||
revalidatePath(toInternalAdminPath(redirectUrl.pathname));
|
revalidatePath(toInternalAdminPath(redirectUrl.pathname));
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
for (const appLocale of routing.locales) {
|
for (const appLocale of routing.locales) {
|
||||||
revalidatePath(getLocalizedPath(appLocale), "layout");
|
revalidatePath(getLocalizedPath(appLocale, "/", siteSettings.defaultLocale), "layout");
|
||||||
revalidatePath(getLocalizedPath(appLocale, "/coming-soon"));
|
revalidatePath(getLocalizedPath(appLocale, "/coming-soon", siteSettings.defaultLocale));
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(`${redirectUrl.pathname}${redirectUrl.search}`);
|
redirect(`${redirectUrl.pathname}${redirectUrl.search}`);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { isRedirectError } from "next/dist/client/components/redirect-error";
|
|||||||
|
|
||||||
import { getAdminAppPath, toInternalAdminPath } from "@/lib/admin-routing";
|
import { getAdminAppPath, toInternalAdminPath } from "@/lib/admin-routing";
|
||||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||||
import { updateMarqueeSettings } from "@/lib/app-config";
|
import { getSiteSettings, updateMarqueeSettings } from "@/lib/app-config";
|
||||||
import { routing } from "@/i18n/routing";
|
import { routing } from "@/i18n/routing";
|
||||||
import { getLocalizedPath } from "@/lib/locale";
|
import { getLocalizedPath } from "@/lib/locale";
|
||||||
|
|
||||||
@@ -27,10 +27,11 @@ function withMessage(pathname: string, type: "success" | "error", message: strin
|
|||||||
async function revalidateMarqueePages() {
|
async function revalidateMarqueePages() {
|
||||||
revalidatePath(toInternalAdminPath("/"));
|
revalidatePath(toInternalAdminPath("/"));
|
||||||
revalidatePath(toInternalAdminPath("/marquee"));
|
revalidatePath(toInternalAdminPath("/marquee"));
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
for (const locale of routing.locales) {
|
for (const locale of routing.locales) {
|
||||||
revalidatePath(getLocalizedPath(locale), "layout");
|
revalidatePath(getLocalizedPath(locale, "/", siteSettings.defaultLocale), "layout");
|
||||||
revalidatePath(getLocalizedPath(locale));
|
revalidatePath(getLocalizedPath(locale, "/", siteSettings.defaultLocale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { removeManagedMediaFile } from "@/lib/media-storage";
|
|||||||
import { mediaFieldInputSchema } from "@/lib/media-validation";
|
import { mediaFieldInputSchema } from "@/lib/media-validation";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { isCheckedFormValue } from "@/lib/form-data";
|
import { isCheckedFormValue } from "@/lib/form-data";
|
||||||
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import {
|
import {
|
||||||
assetInputSchema,
|
assetInputSchema,
|
||||||
categoryInputSchema,
|
categoryInputSchema,
|
||||||
@@ -92,9 +93,10 @@ async function revalidatePortfolioPages() {
|
|||||||
revalidatePath(toInternalAdminPath("/portfolio/categories"));
|
revalidatePath(toInternalAdminPath("/portfolio/categories"));
|
||||||
revalidatePath(toInternalAdminPath("/portfolio/projects"));
|
revalidatePath(toInternalAdminPath("/portfolio/projects"));
|
||||||
revalidatePath("/portfolio");
|
revalidatePath("/portfolio");
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
for (const locale of routing.locales) {
|
for (const locale of routing.locales) {
|
||||||
revalidatePath(getLocalizedPath(locale, "/portfolio"));
|
revalidatePath(getLocalizedPath(locale, "/portfolio", siteSettings.defaultLocale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,9 +522,10 @@ export async function saveProjectAction(formData: FormData) {
|
|||||||
await revalidatePortfolioPages();
|
await revalidatePortfolioPages();
|
||||||
revalidatePath(toInternalAdminPath(`/portfolio/projects/${projectResult.project.id}`));
|
revalidatePath(toInternalAdminPath(`/portfolio/projects/${projectResult.project.id}`));
|
||||||
revalidatePath(`/portfolio/${projectResult.project.slug}`);
|
revalidatePath(`/portfolio/${projectResult.project.slug}`);
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
for (const locale of routing.locales) {
|
for (const locale of routing.locales) {
|
||||||
revalidatePath(getLocalizedPath(locale, `/portfolio/${projectResult.project.slug}`));
|
revalidatePath(getLocalizedPath(locale, `/portfolio/${projectResult.project.slug}`, siteSettings.defaultLocale));
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(
|
redirect(
|
||||||
@@ -591,9 +594,10 @@ export async function deleteProjectAction(formData: FormData) {
|
|||||||
|
|
||||||
await revalidatePortfolioPages();
|
await revalidatePortfolioPages();
|
||||||
revalidatePath(`/portfolio/${project.slug}`);
|
revalidatePath(`/portfolio/${project.slug}`);
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
for (const locale of routing.locales) {
|
for (const locale of routing.locales) {
|
||||||
revalidatePath(getLocalizedPath(locale, `/portfolio/${project.slug}`));
|
revalidatePath(getLocalizedPath(locale, `/portfolio/${project.slug}`, siteSettings.defaultLocale));
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(withMessage(getAdminAppPath("/portfolio"), "success", "Project deleted."));
|
redirect(withMessage(getAdminAppPath("/portfolio"), "success", "Project deleted."));
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ async function cleanupCreatedMedia(assetIds: string[], uploadedPaths: string[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function revalidateSiteSettingsPages() {
|
async function revalidateSiteSettingsPages(defaultLocale: SiteSettings["defaultLocale"]) {
|
||||||
revalidatePath("/", "layout");
|
revalidatePath("/", "layout");
|
||||||
revalidatePath(toInternalAdminPath("/"));
|
revalidatePath(toInternalAdminPath("/"));
|
||||||
revalidatePath(toInternalAdminPath("/site-settings"));
|
revalidatePath(toInternalAdminPath("/site-settings"));
|
||||||
@@ -88,10 +88,10 @@ async function revalidateSiteSettingsPages() {
|
|||||||
const publicPaths = ["/", "/about", "/portfolio", "/contact", "/success", "/coming-soon"];
|
const publicPaths = ["/", "/about", "/portfolio", "/contact", "/success", "/coming-soon"];
|
||||||
|
|
||||||
for (const locale of routing.locales) {
|
for (const locale of routing.locales) {
|
||||||
revalidatePath(getLocalizedPath(locale), "layout");
|
revalidatePath(getLocalizedPath(locale, "/", defaultLocale), "layout");
|
||||||
|
|
||||||
for (const path of publicPaths) {
|
for (const path of publicPaths) {
|
||||||
revalidatePath(getLocalizedPath(locale, path));
|
revalidatePath(getLocalizedPath(locale, path, defaultLocale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +259,7 @@ export async function saveSiteBrandSettingsAction(formData: FormData) {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await revalidateSiteSettingsPages();
|
await revalidateSiteSettingsPages(parsedSettings.defaultLocale);
|
||||||
redirect(withMessage(getAdminAppPath("/site-settings/brand"), "success", "Einstellungen gespeichert."));
|
redirect(withMessage(getAdminAppPath("/site-settings/brand"), "success", "Einstellungen gespeichert."));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isRedirectError(error)) {
|
if (isRedirectError(error)) {
|
||||||
@@ -321,7 +321,7 @@ export async function saveSiteLocalizationSettingsAction(formData: FormData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await updateSiteSettings(parsedSettings);
|
await updateSiteSettings(parsedSettings);
|
||||||
await revalidateSiteSettingsPages();
|
await revalidateSiteSettingsPages(parsedSettings.defaultLocale);
|
||||||
redirect(withMessage(getAdminAppPath("/site-settings/localization"), "success", "Einstellungen gespeichert."));
|
redirect(withMessage(getAdminAppPath("/site-settings/localization"), "success", "Einstellungen gespeichert."));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isRedirectError(error)) {
|
if (isRedirectError(error)) {
|
||||||
|
|||||||
+10
-7
@@ -2,6 +2,7 @@ import type { MetadataRoute } from "next";
|
|||||||
import { unstable_noStore as noStore } from "next/cache";
|
import { unstable_noStore as noStore } from "next/cache";
|
||||||
|
|
||||||
import { routing } from "@/i18n/routing";
|
import { routing } from "@/i18n/routing";
|
||||||
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import { getLocalizedPath } from "@/lib/locale";
|
import { getLocalizedPath } from "@/lib/locale";
|
||||||
import { getPublishedPortfolioProjects } from "@/lib/portfolio";
|
import { getPublishedPortfolioProjects } from "@/lib/portfolio";
|
||||||
|
|
||||||
@@ -15,10 +16,11 @@ function toAbsoluteUrl(pathname: string): string {
|
|||||||
|
|
||||||
function buildLocalizedEntries(
|
function buildLocalizedEntries(
|
||||||
pathname: string,
|
pathname: string,
|
||||||
|
defaultLocale: "de" | "en" | "ar",
|
||||||
options?: Pick<MetadataRoute.Sitemap[number], "changeFrequency" | "priority" | "lastModified">,
|
options?: Pick<MetadataRoute.Sitemap[number], "changeFrequency" | "priority" | "lastModified">,
|
||||||
): MetadataRoute.Sitemap {
|
): MetadataRoute.Sitemap {
|
||||||
return routing.locales.map((locale) => ({
|
return routing.locales.map((locale) => ({
|
||||||
url: toAbsoluteUrl(getLocalizedPath(locale, pathname)),
|
url: toAbsoluteUrl(getLocalizedPath(locale, pathname, defaultLocale)),
|
||||||
lastModified: options?.lastModified,
|
lastModified: options?.lastModified,
|
||||||
changeFrequency: options?.changeFrequency,
|
changeFrequency: options?.changeFrequency,
|
||||||
priority: options?.priority,
|
priority: options?.priority,
|
||||||
@@ -27,6 +29,7 @@ function buildLocalizedEntries(
|
|||||||
|
|
||||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||||
noStore();
|
noStore();
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
let projects: Awaited<ReturnType<typeof getPublishedPortfolioProjects>> = [];
|
let projects: Awaited<ReturnType<typeof getPublishedPortfolioProjects>> = [];
|
||||||
|
|
||||||
@@ -41,30 +44,30 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...buildLocalizedEntries("/", {
|
...buildLocalizedEntries("/", siteSettings.defaultLocale, {
|
||||||
changeFrequency: "weekly",
|
changeFrequency: "weekly",
|
||||||
priority: 1,
|
priority: 1,
|
||||||
}),
|
}),
|
||||||
...buildLocalizedEntries("/about", {
|
...buildLocalizedEntries("/about", siteSettings.defaultLocale, {
|
||||||
changeFrequency: "monthly",
|
changeFrequency: "monthly",
|
||||||
priority: 0.8,
|
priority: 0.8,
|
||||||
}),
|
}),
|
||||||
...buildLocalizedEntries("/portfolio", {
|
...buildLocalizedEntries("/portfolio", siteSettings.defaultLocale, {
|
||||||
changeFrequency: "weekly",
|
changeFrequency: "weekly",
|
||||||
priority: 0.9,
|
priority: 0.9,
|
||||||
}),
|
}),
|
||||||
...categories.flatMap((category) =>
|
...categories.flatMap((category) =>
|
||||||
buildLocalizedEntries(`/portfolio/category/${category.slug}`, {
|
buildLocalizedEntries(`/portfolio/category/${category.slug}`, siteSettings.defaultLocale, {
|
||||||
changeFrequency: "weekly",
|
changeFrequency: "weekly",
|
||||||
priority: 0.8,
|
priority: 0.8,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
...buildLocalizedEntries("/contact", {
|
...buildLocalizedEntries("/contact", siteSettings.defaultLocale, {
|
||||||
changeFrequency: "monthly",
|
changeFrequency: "monthly",
|
||||||
priority: 0.7,
|
priority: 0.7,
|
||||||
}),
|
}),
|
||||||
...projects.flatMap((project) =>
|
...projects.flatMap((project) =>
|
||||||
buildLocalizedEntries(`/portfolio/${project.slug}`, {
|
buildLocalizedEntries(`/portfolio/${project.slug}`, siteSettings.defaultLocale, {
|
||||||
lastModified: project.publishedAt ?? undefined,
|
lastModified: project.publishedAt ?? undefined,
|
||||||
changeFrequency: "monthly",
|
changeFrequency: "monthly",
|
||||||
priority: 0.8,
|
priority: 0.8,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { Badge } from "@/components/ui/badge";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CardContent } from "@/components/ui/card";
|
import { CardContent } from "@/components/ui/card";
|
||||||
import { getAdminAppPath } from "@/lib/admin-routing";
|
import { getAdminAppPath } from "@/lib/admin-routing";
|
||||||
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
import { getLocalizedPath } from "@/lib/locale";
|
import { getLocalizedPath } from "@/lib/locale";
|
||||||
import { getLocalizedValue, type PortfolioCategoryView, type PortfolioProjectView } from "@/lib/portfolio";
|
import { getLocalizedValue, type PortfolioCategoryView, type PortfolioProjectView } from "@/lib/portfolio";
|
||||||
|
|
||||||
@@ -28,11 +29,13 @@ const copy = {
|
|||||||
empty: "Noch keine Projekte vorhanden.",
|
empty: "Noch keine Projekte vorhanden.",
|
||||||
};
|
};
|
||||||
|
|
||||||
export function PortfolioProjectsOverview({
|
export async function PortfolioProjectsOverview({
|
||||||
categories,
|
categories,
|
||||||
projects,
|
projects,
|
||||||
selectedCategory,
|
selectedCategory,
|
||||||
}: PortfolioProjectsOverviewProps) {
|
}: PortfolioProjectsOverviewProps) {
|
||||||
|
const siteSettings = await getSiteSettings();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="flex flex-col gap-4 xl:flex-row xl:items-end xl:justify-between">
|
<div className="flex flex-col gap-4 xl:flex-row xl:items-end xl:justify-between">
|
||||||
@@ -102,7 +105,7 @@ export function PortfolioProjectsOverview({
|
|||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-3">
|
||||||
<Button asChild variant="outline">
|
<Button asChild variant="outline">
|
||||||
<Link
|
<Link
|
||||||
href={getLocalizedPath("de", `/portfolio/${project.slug}`)}
|
href={getLocalizedPath("de", `/portfolio/${project.slug}`, siteSettings.defaultLocale)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const PENDING_TOAST_STORAGE_KEY = "mohfarawati-pending-toast";
|
|||||||
|
|
||||||
type LocaleToggleProps = {
|
type LocaleToggleProps = {
|
||||||
locale: string;
|
locale: string;
|
||||||
defaultLocale?: AppLocale;
|
defaultLocale: AppLocale;
|
||||||
className?: string;
|
className?: string;
|
||||||
showLabel?: boolean;
|
showLabel?: boolean;
|
||||||
};
|
};
|
||||||
@@ -30,7 +30,7 @@ const localeChangedMessages: Record<AppLocale, string> = {
|
|||||||
|
|
||||||
export function LocaleToggle({
|
export function LocaleToggle({
|
||||||
locale,
|
locale,
|
||||||
defaultLocale = "de",
|
defaultLocale,
|
||||||
className,
|
className,
|
||||||
showLabel = false,
|
showLabel = false,
|
||||||
}: LocaleToggleProps) {
|
}: LocaleToggleProps) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { cn } from "@/lib/utils";
|
|||||||
|
|
||||||
type PortfolioCategoryFilterProps = {
|
type PortfolioCategoryFilterProps = {
|
||||||
locale: AppLocale;
|
locale: AppLocale;
|
||||||
|
defaultLocale: AppLocale;
|
||||||
categories: PortfolioCategoryView[];
|
categories: PortfolioCategoryView[];
|
||||||
allLabel: string;
|
allLabel: string;
|
||||||
activeCategorySlug?: string;
|
activeCategorySlug?: string;
|
||||||
@@ -14,6 +15,7 @@ type PortfolioCategoryFilterProps = {
|
|||||||
|
|
||||||
export function PortfolioCategoryFilter({
|
export function PortfolioCategoryFilter({
|
||||||
locale,
|
locale,
|
||||||
|
defaultLocale,
|
||||||
categories,
|
categories,
|
||||||
allLabel,
|
allLabel,
|
||||||
activeCategorySlug,
|
activeCategorySlug,
|
||||||
@@ -21,14 +23,14 @@ export function PortfolioCategoryFilter({
|
|||||||
return (
|
return (
|
||||||
<section className="flex flex-wrap gap-3">
|
<section className="flex flex-wrap gap-3">
|
||||||
<CategoryLink
|
<CategoryLink
|
||||||
href={getLocalizedPath(locale, "/portfolio")}
|
href={getLocalizedPath(locale, "/portfolio", defaultLocale)}
|
||||||
label={allLabel}
|
label={allLabel}
|
||||||
active={!activeCategorySlug}
|
active={!activeCategorySlug}
|
||||||
/>
|
/>
|
||||||
{categories.map((category) => (
|
{categories.map((category) => (
|
||||||
<CategoryLink
|
<CategoryLink
|
||||||
key={category.id}
|
key={category.id}
|
||||||
href={getLocalizedPath(locale, `/portfolio/category/${category.slug}`)}
|
href={getLocalizedPath(locale, `/portfolio/category/${category.slug}`, defaultLocale)}
|
||||||
label={getLocalizedValue(category.name, locale)}
|
label={getLocalizedValue(category.name, locale)}
|
||||||
active={activeCategorySlug === category.slug}
|
active={activeCategorySlug === category.slug}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {
|
|||||||
type PortfolioProjectDetailProps = {
|
type PortfolioProjectDetailProps = {
|
||||||
item: PortfolioProjectView;
|
item: PortfolioProjectView;
|
||||||
locale: AppLocale;
|
locale: AppLocale;
|
||||||
|
defaultLocale: AppLocale;
|
||||||
t: (key: "back" | "preview" | "openLink" | "gallery" | "download") => string;
|
t: (key: "back" | "preview" | "openLink" | "gallery" | "download") => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -223,10 +224,12 @@ function BadgeCount({ count }: { count: number }) {
|
|||||||
function ProjectHeader({
|
function ProjectHeader({
|
||||||
item,
|
item,
|
||||||
locale,
|
locale,
|
||||||
|
defaultLocale,
|
||||||
t,
|
t,
|
||||||
}: {
|
}: {
|
||||||
item: PortfolioProjectView;
|
item: PortfolioProjectView;
|
||||||
locale: AppLocale;
|
locale: AppLocale;
|
||||||
|
defaultLocale: AppLocale;
|
||||||
t: PortfolioProjectDetailProps["t"];
|
t: PortfolioProjectDetailProps["t"];
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
@@ -234,7 +237,7 @@ function ProjectHeader({
|
|||||||
<AppCard level={3}>
|
<AppCard level={3}>
|
||||||
<CardContent className="p-6 lg:p-10">
|
<CardContent className="p-6 lg:p-10">
|
||||||
<Button asChild variant="ghost" className="h-auto px-0 py-0 text-sm">
|
<Button asChild variant="ghost" className="h-auto px-0 py-0 text-sm">
|
||||||
<Link href={getLocalizedPath(locale, "/portfolio")}>{t("back")}</Link>
|
<Link href={getLocalizedPath(locale, "/portfolio", defaultLocale)}>{t("back")}</Link>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<h1 className="mt-5 text-3xl font-semibold text-foreground sm:text-4xl lg:text-5xl">
|
<h1 className="mt-5 text-3xl font-semibold text-foreground sm:text-4xl lg:text-5xl">
|
||||||
@@ -267,11 +270,12 @@ function ProjectHeader({
|
|||||||
function GridTemplate({
|
function GridTemplate({
|
||||||
item,
|
item,
|
||||||
locale,
|
locale,
|
||||||
|
defaultLocale,
|
||||||
t,
|
t,
|
||||||
}: PortfolioProjectDetailProps) {
|
}: PortfolioProjectDetailProps) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<ProjectHeader item={item} locale={locale} t={t} />
|
<ProjectHeader item={item} locale={locale} defaultLocale={defaultLocale} t={t} />
|
||||||
|
|
||||||
{item.coverImagePath ? (
|
{item.coverImagePath ? (
|
||||||
<MotionFade delay={0.04}>
|
<MotionFade delay={0.04}>
|
||||||
@@ -309,11 +313,12 @@ function GridTemplate({
|
|||||||
function StoryTemplate({
|
function StoryTemplate({
|
||||||
item,
|
item,
|
||||||
locale,
|
locale,
|
||||||
|
defaultLocale,
|
||||||
t,
|
t,
|
||||||
}: PortfolioProjectDetailProps) {
|
}: PortfolioProjectDetailProps) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
<ProjectHeader item={item} locale={locale} t={t} />
|
<ProjectHeader item={item} locale={locale} defaultLocale={defaultLocale} t={t} />
|
||||||
|
|
||||||
{item.coverImagePath ? (
|
{item.coverImagePath ? (
|
||||||
<MotionFade delay={0.04}>
|
<MotionFade delay={0.04}>
|
||||||
@@ -356,6 +361,7 @@ function StoryTemplate({
|
|||||||
function CaseStudyTemplate({
|
function CaseStudyTemplate({
|
||||||
item,
|
item,
|
||||||
locale,
|
locale,
|
||||||
|
defaultLocale,
|
||||||
t,
|
t,
|
||||||
}: PortfolioProjectDetailProps) {
|
}: PortfolioProjectDetailProps) {
|
||||||
const [challenge, solution, outcome, ...restSections] = item.sections;
|
const [challenge, solution, outcome, ...restSections] = item.sections;
|
||||||
@@ -365,7 +371,7 @@ function CaseStudyTemplate({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
<ProjectHeader item={item} locale={locale} t={t} />
|
<ProjectHeader item={item} locale={locale} defaultLocale={defaultLocale} t={t} />
|
||||||
|
|
||||||
<div className="grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_420px]">
|
<div className="grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_420px]">
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
@@ -441,17 +447,18 @@ function CaseStudyTemplate({
|
|||||||
export function PortfolioProjectDetail({
|
export function PortfolioProjectDetail({
|
||||||
item,
|
item,
|
||||||
locale,
|
locale,
|
||||||
|
defaultLocale,
|
||||||
t,
|
t,
|
||||||
}: PortfolioProjectDetailProps) {
|
}: PortfolioProjectDetailProps) {
|
||||||
const viewMode = resolvePortfolioProjectViewMode(item.viewMode);
|
const viewMode = resolvePortfolioProjectViewMode(item.viewMode);
|
||||||
|
|
||||||
if (viewMode === "STORY") {
|
if (viewMode === "STORY") {
|
||||||
return <StoryTemplate item={item} locale={locale} t={t} />;
|
return <StoryTemplate item={item} locale={locale} defaultLocale={defaultLocale} t={t} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewMode === "CASE_STUDY") {
|
if (viewMode === "CASE_STUDY") {
|
||||||
return <CaseStudyTemplate item={item} locale={locale} t={t} />;
|
return <CaseStudyTemplate item={item} locale={locale} defaultLocale={defaultLocale} t={t} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <GridTemplate item={item} locale={locale} t={t} />;
|
return <GridTemplate item={item} locale={locale} defaultLocale={defaultLocale} t={t} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { getLocalizedValue, type PortfolioProjectView } from "@/lib/portfolio";
|
|||||||
|
|
||||||
type PortfolioProjectGridProps = {
|
type PortfolioProjectGridProps = {
|
||||||
locale: AppLocale;
|
locale: AppLocale;
|
||||||
|
defaultLocale: AppLocale;
|
||||||
projects: PortfolioProjectView[];
|
projects: PortfolioProjectView[];
|
||||||
emptyLabel: string;
|
emptyLabel: string;
|
||||||
openLabel: string;
|
openLabel: string;
|
||||||
@@ -16,6 +17,7 @@ type PortfolioProjectGridProps = {
|
|||||||
|
|
||||||
export function PortfolioProjectGrid({
|
export function PortfolioProjectGrid({
|
||||||
locale,
|
locale,
|
||||||
|
defaultLocale,
|
||||||
projects,
|
projects,
|
||||||
emptyLabel,
|
emptyLabel,
|
||||||
openLabel,
|
openLabel,
|
||||||
@@ -27,7 +29,7 @@ export function PortfolioProjectGrid({
|
|||||||
<AppCard interactive>
|
<AppCard interactive>
|
||||||
<CardContent className="p-5">
|
<CardContent className="p-5">
|
||||||
<Link
|
<Link
|
||||||
href={getLocalizedPath(locale, `/portfolio/${item.slug}`)}
|
href={getLocalizedPath(locale, `/portfolio/${item.slug}`, defaultLocale)}
|
||||||
className="group block"
|
className="group block"
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between gap-3">
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
|||||||
+2
-4
@@ -1,15 +1,13 @@
|
|||||||
import { getRequestConfig } from "next-intl/server";
|
import { getRequestConfig } from "next-intl/server";
|
||||||
|
|
||||||
import { getSiteSettings } from "@/lib/app-config";
|
import { getSiteSettings } from "@/lib/app-config";
|
||||||
|
import { isSupportedLocale } from "@/lib/locale";
|
||||||
import { routing } from "./routing";
|
|
||||||
|
|
||||||
export default getRequestConfig(async ({ requestLocale }) => {
|
export default getRequestConfig(async ({ requestLocale }) => {
|
||||||
const siteSettings = await getSiteSettings();
|
const siteSettings = await getSiteSettings();
|
||||||
const requestedLocale = await requestLocale;
|
const requestedLocale = await requestLocale;
|
||||||
const locale =
|
const locale =
|
||||||
requestedLocale &&
|
isSupportedLocale(requestedLocale)
|
||||||
routing.locales.includes(requestedLocale as (typeof routing.locales)[number])
|
|
||||||
? requestedLocale
|
? requestedLocale
|
||||||
: siteSettings.defaultLocale;
|
: siteSettings.defaultLocale;
|
||||||
|
|
||||||
|
|||||||
+13
-11
@@ -1,21 +1,23 @@
|
|||||||
import { routing } from "../i18n/routing";
|
import { appLocales } from "../i18n/routing";
|
||||||
|
|
||||||
export type AppLocale = (typeof routing.locales)[number];
|
export type AppLocale = (typeof appLocales)[number];
|
||||||
|
|
||||||
export function resolveLocale(locale: string): AppLocale {
|
export const FALLBACK_LOCALE: AppLocale = "de";
|
||||||
if (locale === "en" || locale === "ar") {
|
|
||||||
return locale;
|
export function isSupportedLocale(locale: string | undefined | null): locale is AppLocale {
|
||||||
|
return locale === "de" || locale === "en" || locale === "ar";
|
||||||
}
|
}
|
||||||
|
|
||||||
return routing.defaultLocale;
|
export function resolveLocale(locale: string | undefined | null, fallbackLocale: AppLocale): AppLocale {
|
||||||
|
return isSupportedLocale(locale) ? locale : fallbackLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDirection(locale: string): "ltr" | "rtl" {
|
export function getDirection(locale: string): "ltr" | "rtl" {
|
||||||
return resolveLocale(locale) === "ar" ? "rtl" : "ltr";
|
return locale === "ar" ? "rtl" : "ltr";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stripLocalePrefix(pathname: string): string {
|
export function stripLocalePrefix(pathname: string): string {
|
||||||
for (const locale of routing.locales) {
|
for (const locale of appLocales) {
|
||||||
if (pathname === `/${locale}`) {
|
if (pathname === `/${locale}`) {
|
||||||
return "/";
|
return "/";
|
||||||
}
|
}
|
||||||
@@ -31,7 +33,7 @@ export function stripLocalePrefix(pathname: string): string {
|
|||||||
export function getLocalizedPath(
|
export function getLocalizedPath(
|
||||||
locale: string,
|
locale: string,
|
||||||
pathname = "/",
|
pathname = "/",
|
||||||
defaultLocale: AppLocale = routing.defaultLocale,
|
defaultLocale: AppLocale,
|
||||||
): string {
|
): string {
|
||||||
return getLocalizedPathWithDefault(locale, pathname, defaultLocale);
|
return getLocalizedPathWithDefault(locale, pathname, defaultLocale);
|
||||||
}
|
}
|
||||||
@@ -39,9 +41,9 @@ export function getLocalizedPath(
|
|||||||
export function getLocalizedPathWithDefault(
|
export function getLocalizedPathWithDefault(
|
||||||
locale: string,
|
locale: string,
|
||||||
pathname = "/",
|
pathname = "/",
|
||||||
defaultLocale: AppLocale = routing.defaultLocale,
|
defaultLocale: AppLocale,
|
||||||
): string {
|
): string {
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, defaultLocale);
|
||||||
const normalizedPath = pathname === "" ? "/" : pathname;
|
const normalizedPath = pathname === "" ? "/" : pathname;
|
||||||
const strippedPath = stripLocalePrefix(normalizedPath);
|
const strippedPath = stripLocalePrefix(normalizedPath);
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -1,6 +1,6 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
|
|
||||||
import { routing } from "../i18n/routing";
|
import { appLocales } from "../i18n/routing";
|
||||||
import {
|
import {
|
||||||
PAGE_TITLE_TOKEN,
|
PAGE_TITLE_TOKEN,
|
||||||
SITE_NAME_TOKEN,
|
SITE_NAME_TOKEN,
|
||||||
@@ -22,9 +22,9 @@ function toAbsoluteUrl(pathname: string): string {
|
|||||||
return new URL(pathname, getSiteUrl()).toString();
|
return new URL(pathname, getSiteUrl()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildLocaleAlternates(pathname: string, defaultLocale = routing.defaultLocale) {
|
export function buildLocaleAlternates(pathname: string, defaultLocale: AppLocale) {
|
||||||
const languages = Object.fromEntries(
|
const languages = Object.fromEntries(
|
||||||
routing.locales.map((locale) => [locale, toAbsoluteUrl(getLocalizedPathWithDefault(locale, pathname, defaultLocale))]),
|
appLocales.map((locale) => [locale, toAbsoluteUrl(getLocalizedPathWithDefault(locale, pathname, defaultLocale))]),
|
||||||
) as Record<AppLocale, string>;
|
) as Record<AppLocale, string>;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -120,8 +120,8 @@ export async function buildLocalizedMetadata({
|
|||||||
description,
|
description,
|
||||||
applyTitleTemplate,
|
applyTitleTemplate,
|
||||||
}: LocalizedMetadataInput): Promise<Metadata> {
|
}: LocalizedMetadataInput): Promise<Metadata> {
|
||||||
const localeKey = resolveLocale(locale);
|
|
||||||
const [settings, bindings] = await Promise.all([getSiteSettings(), getSiteSettingsMediaBindings()]);
|
const [settings, bindings] = await Promise.all([getSiteSettings(), getSiteSettingsMediaBindings()]);
|
||||||
|
const localeKey = resolveLocale(locale, settings.defaultLocale);
|
||||||
|
|
||||||
return buildLocalizedMetadataFromConfig({
|
return buildLocalizedMetadataFromConfig({
|
||||||
settings,
|
settings,
|
||||||
@@ -152,7 +152,7 @@ export function buildLocalizedMetadataFromConfig(input: {
|
|||||||
description,
|
description,
|
||||||
applyTitleTemplate = true,
|
applyTitleTemplate = true,
|
||||||
} = input;
|
} = input;
|
||||||
const localeKey = resolveLocale(locale);
|
const localeKey = resolveLocale(locale, settings.defaultLocale);
|
||||||
const localeSettings = settings.locales[localeKey];
|
const localeSettings = settings.locales[localeKey];
|
||||||
const resolvedDescription = description?.trim() || localeSettings.siteDescription;
|
const resolvedDescription = description?.trim() || localeSettings.siteDescription;
|
||||||
const resolvedTitle = applyTitleTemplate
|
const resolvedTitle = applyTitleTemplate
|
||||||
@@ -167,7 +167,7 @@ export function buildLocalizedMetadataFromConfig(input: {
|
|||||||
openGraph: {
|
openGraph: {
|
||||||
title: resolvedTitle,
|
title: resolvedTitle,
|
||||||
description: resolvedDescription,
|
description: resolvedDescription,
|
||||||
url: toAbsoluteUrl(getLocalizedPath(localeKey, pathname)),
|
url: toAbsoluteUrl(getLocalizedPath(localeKey, pathname, settings.defaultLocale)),
|
||||||
siteName: localeSettings.siteName,
|
siteName: localeSettings.siteName,
|
||||||
locale: localeKey,
|
locale: localeKey,
|
||||||
type: "website",
|
type: "website",
|
||||||
|
|||||||
+4
-4
@@ -6,7 +6,7 @@ import {
|
|||||||
type ToastPosition,
|
type ToastPosition,
|
||||||
} from "react-hot-toast";
|
} from "react-hot-toast";
|
||||||
|
|
||||||
import { resolveLocale } from "@/lib/locale";
|
import { FALLBACK_LOCALE, resolveLocale } from "@/lib/locale";
|
||||||
|
|
||||||
type ToastVariant = "default" | "success" | "error" | "loading";
|
type ToastVariant = "default" | "success" | "error" | "loading";
|
||||||
|
|
||||||
@@ -14,13 +14,13 @@ type ToastMessage = string;
|
|||||||
|
|
||||||
function getCurrentLocale() {
|
function getCurrentLocale() {
|
||||||
if (typeof window === "undefined") {
|
if (typeof window === "undefined") {
|
||||||
return "de" as const;
|
return FALLBACK_LOCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathname = window.location.pathname;
|
const pathname = window.location.pathname;
|
||||||
const maybeLocale = pathname.split("/")[1] || "de";
|
const maybeLocale = pathname.split("/")[1] || FALLBACK_LOCALE;
|
||||||
|
|
||||||
return resolveLocale(maybeLocale);
|
return resolveLocale(maybeLocale, FALLBACK_LOCALE);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToastPosition(isArabic: boolean): ToastPosition {
|
function getToastPosition(isArabic: boolean): ToastPosition {
|
||||||
|
|||||||
+10
-9
@@ -2,7 +2,7 @@ import createMiddleware from "next-intl/middleware";
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import type { NextRequest } from "next/server";
|
import type { NextRequest } from "next/server";
|
||||||
|
|
||||||
import { appLocales, createI18nRouting, routing } from "./i18n/routing";
|
import { appLocales, createI18nRouting } from "./i18n/routing";
|
||||||
import {
|
import {
|
||||||
fromDevelopmentAdminPath,
|
fromDevelopmentAdminPath,
|
||||||
getAdminBaseUrl,
|
getAdminBaseUrl,
|
||||||
@@ -14,7 +14,12 @@ import {
|
|||||||
isLegacyAdminPath,
|
isLegacyAdminPath,
|
||||||
toInternalAdminPath,
|
toInternalAdminPath,
|
||||||
} from "./lib/admin-routing";
|
} from "./lib/admin-routing";
|
||||||
import { getLocalizedPathWithDefault, stripLocalePrefix } from "./lib/locale";
|
import {
|
||||||
|
FALLBACK_LOCALE,
|
||||||
|
getLocalizedPathWithDefault,
|
||||||
|
isSupportedLocale,
|
||||||
|
stripLocalePrefix,
|
||||||
|
} from "./lib/locale";
|
||||||
|
|
||||||
const ADMIN_SESSION_COOKIE = "moh_admin_session";
|
const ADMIN_SESSION_COOKIE = "moh_admin_session";
|
||||||
|
|
||||||
@@ -23,10 +28,6 @@ type SiteRuntimeState = {
|
|||||||
maintenanceEnabled: boolean;
|
maintenanceEnabled: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function isSupportedLocale(locale: string | undefined): locale is (typeof appLocales)[number] {
|
|
||||||
return locale === "ar" || locale === "en" || locale === "de";
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPathLocale(pathname: string, fallbackLocale: (typeof appLocales)[number]) {
|
function getPathLocale(pathname: string, fallbackLocale: (typeof appLocales)[number]) {
|
||||||
const locale = pathname.split("/")[1];
|
const locale = pathname.split("/")[1];
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeSta
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return {
|
return {
|
||||||
defaultLocale: routing.defaultLocale,
|
defaultLocale: FALLBACK_LOCALE,
|
||||||
maintenanceEnabled: false,
|
maintenanceEnabled: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -59,12 +60,12 @@ async function getSiteRuntimeState(request: NextRequest): Promise<SiteRuntimeSta
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaultLocale: isSupportedLocale(data.defaultLocale) ? data.defaultLocale : routing.defaultLocale,
|
defaultLocale: isSupportedLocale(data.defaultLocale) ? data.defaultLocale : FALLBACK_LOCALE,
|
||||||
maintenanceEnabled: data.maintenanceEnabled === true,
|
maintenanceEnabled: data.maintenanceEnabled === true,
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
return {
|
return {
|
||||||
defaultLocale: routing.defaultLocale,
|
defaultLocale: FALLBACK_LOCALE,
|
||||||
maintenanceEnabled: false,
|
maintenanceEnabled: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -1,8 +1,22 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { getLocalizedPathWithDefault } from "../lib/locale";
|
import { FALLBACK_LOCALE, getLocalizedPathWithDefault, isSupportedLocale, resolveLocale } from "../lib/locale";
|
||||||
|
|
||||||
describe("locale path helpers", () => {
|
describe("locale path helpers", () => {
|
||||||
|
it("recognizes supported locales explicitly", () => {
|
||||||
|
expect(isSupportedLocale("ar")).toBe(true);
|
||||||
|
expect(isSupportedLocale("en")).toBe(true);
|
||||||
|
expect(isSupportedLocale("de")).toBe(true);
|
||||||
|
expect(isSupportedLocale("fr")).toBe(false);
|
||||||
|
expect(isSupportedLocale(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resolves invalid locales with an explicit fallback", () => {
|
||||||
|
expect(resolveLocale("ar", "de")).toBe("ar");
|
||||||
|
expect(resolveLocale("fr", "en")).toBe("en");
|
||||||
|
expect(resolveLocale("", FALLBACK_LOCALE)).toBe("de");
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps the configured default locale on the bare domain", () => {
|
it("keeps the configured default locale on the bare domain", () => {
|
||||||
expect(getLocalizedPathWithDefault("ar", "/", "ar")).toBe("/");
|
expect(getLocalizedPathWithDefault("ar", "/", "ar")).toBe("/");
|
||||||
expect(getLocalizedPathWithDefault("de", "/", "ar")).toBe("/de");
|
expect(getLocalizedPathWithDefault("de", "/", "ar")).toBe("/de");
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { buildDefaultSiteSettings } from "../lib/site-settings";
|
|||||||
import {
|
import {
|
||||||
applyTitleTemplateFn,
|
applyTitleTemplateFn,
|
||||||
buildAppMetadataFromConfig,
|
buildAppMetadataFromConfig,
|
||||||
|
buildLocaleAlternates,
|
||||||
buildLocalizedMetadataFromConfig,
|
buildLocalizedMetadataFromConfig,
|
||||||
} from "../lib/metadata";
|
} from "../lib/metadata";
|
||||||
|
|
||||||
@@ -96,4 +97,44 @@ describe("metadata helpers", () => {
|
|||||||
|
|
||||||
expect(metadata.title).toBe("اسم الموقع");
|
expect(metadata.title).toBe("اسم الموقع");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("builds alternates and canonical from the runtime default locale", () => {
|
||||||
|
const alternates = buildLocaleAlternates("/about", "ar");
|
||||||
|
|
||||||
|
expect(alternates.canonical).toBe("https://mohfarawati.de/about");
|
||||||
|
expect(alternates.languages.ar).toBe("https://mohfarawati.de/about");
|
||||||
|
expect(alternates.languages.de).toBe("https://mohfarawati.de/de/about");
|
||||||
|
expect(alternates.languages["x-default"]).toBe("https://mohfarawati.de/about");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("builds localized metadata urls against the configured default locale", () => {
|
||||||
|
const settings = buildDefaultSiteSettings("Studio Moh");
|
||||||
|
settings.defaultLocale = "ar";
|
||||||
|
|
||||||
|
const metadata = buildLocalizedMetadataFromConfig({
|
||||||
|
settings,
|
||||||
|
bindings: {
|
||||||
|
siteLogoLight: null,
|
||||||
|
siteLogoDark: null,
|
||||||
|
favicon: null,
|
||||||
|
defaultOgImage: null,
|
||||||
|
},
|
||||||
|
locale: "de",
|
||||||
|
pathname: "/about",
|
||||||
|
title: "About",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(metadata.alternates).toMatchObject({
|
||||||
|
canonical: "https://mohfarawati.de/about",
|
||||||
|
languages: {
|
||||||
|
ar: "https://mohfarawati.de/about",
|
||||||
|
de: "https://mohfarawati.de/de/about",
|
||||||
|
en: "https://mohfarawati.de/en/about",
|
||||||
|
"x-default": "https://mohfarawati.de/about",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(metadata.openGraph).toMatchObject({
|
||||||
|
url: "https://mohfarawati.de/de/about",
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
const createMiddlewareMock = vi.fn();
|
||||||
|
const intlHandlerMock = vi.fn(() => NextResponse.next());
|
||||||
|
|
||||||
|
vi.mock("next-intl/middleware", () => ({
|
||||||
|
default: createMiddlewareMock,
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("../lib/admin-routing", () => ({
|
||||||
|
fromDevelopmentAdminPath: (pathname: string) => pathname,
|
||||||
|
getAdminBaseUrl: () => "https://admin.example.com",
|
||||||
|
getRequestHostname: (_forwardedHost: string | null, host: string | null, hostname: string) => host ?? hostname,
|
||||||
|
isDevelopmentAdminPath: () => false,
|
||||||
|
isAdminHost: () => false,
|
||||||
|
hasDedicatedAdminHost: () => false,
|
||||||
|
isInternalAdminPath: () => false,
|
||||||
|
isLegacyAdminPath: () => false,
|
||||||
|
toInternalAdminPath: (pathname: string) => pathname,
|
||||||
|
}));
|
||||||
|
|
||||||
|
function createMockRequest(url: string) {
|
||||||
|
const nextUrl = new URL(url) as URL & { clone: () => URL };
|
||||||
|
nextUrl.clone = () => new URL(nextUrl.toString());
|
||||||
|
|
||||||
|
return {
|
||||||
|
url,
|
||||||
|
nextUrl,
|
||||||
|
headers: new Headers({
|
||||||
|
host: nextUrl.host,
|
||||||
|
}),
|
||||||
|
cookies: {
|
||||||
|
has: vi.fn(() => false),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("middleware locale runtime config", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.resetModules();
|
||||||
|
createMiddlewareMock.mockReset();
|
||||||
|
intlHandlerMock.mockReset();
|
||||||
|
intlHandlerMock.mockReturnValue(NextResponse.next());
|
||||||
|
createMiddlewareMock.mockReturnValue(intlHandlerMock);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.unstubAllGlobals();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes the runtime default locale into next-intl middleware", async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
"fetch",
|
||||||
|
vi.fn(async () => ({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
defaultLocale: "ar",
|
||||||
|
maintenanceEnabled: false,
|
||||||
|
}),
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { default: middleware } = await import("../middleware");
|
||||||
|
const request = createMockRequest("https://example.com/");
|
||||||
|
|
||||||
|
await middleware(request as never);
|
||||||
|
|
||||||
|
expect(createMiddlewareMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(createMiddlewareMock).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
defaultLocale: "ar",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(intlHandlerMock).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back safely when the runtime locale lookup fails", async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
"fetch",
|
||||||
|
vi.fn(async () => {
|
||||||
|
throw new Error("network failed");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { default: middleware } = await import("../middleware");
|
||||||
|
const request = createMockRequest("https://example.com/");
|
||||||
|
|
||||||
|
await middleware(request as never);
|
||||||
|
|
||||||
|
expect(createMiddlewareMock).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
defaultLocale: "de",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("redirects maintenance traffic using the runtime default locale", async () => {
|
||||||
|
vi.stubGlobal(
|
||||||
|
"fetch",
|
||||||
|
vi.fn(async () => ({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
defaultLocale: "ar",
|
||||||
|
maintenanceEnabled: true,
|
||||||
|
}),
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { default: middleware } = await import("../middleware");
|
||||||
|
const request = createMockRequest("https://example.com/");
|
||||||
|
|
||||||
|
const response = await middleware(request as never);
|
||||||
|
|
||||||
|
expect(response.headers.get("location")).toBe("https://example.com/coming-soon");
|
||||||
|
expect(intlHandlerMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user