diff --git a/proto/src/app/(frontend)/[locale]/[slug]/page.tsx b/proto/src/app/(frontend)/[locale]/[slug]/page.tsx new file mode 100644 index 0000000..6b7b614 --- /dev/null +++ b/proto/src/app/(frontend)/[locale]/[slug]/page.tsx @@ -0,0 +1,128 @@ +import type { Metadata } from 'next' +import { notFound } from 'next/navigation' +import AboutView from '@/components/views/AboutView' +import ServicesView from '@/components/views/ServicesView' +import ContactView from '@/components/views/ContactView' +import LegalPageView from '@/components/views/LegalPageView' +import { LOCALES, PAGE_SLUGS, resolvePageKey, isLocale, type Locale, type PageKey } from '@/lib/i18n' +import { + getAboutContent, + getServicesContent, + getContactContent, + getHomeContent, + getCommonContent, + getLegalPage, +} from '@/lib/payload-content' +import { siteConfig, getOgLocale } from '@/config/site' + +type Params = { locale: string; slug: string } + +export function generateStaticParams() { + return LOCALES.flatMap((locale) => + (Object.keys(PAGE_SLUGS) as PageKey[]).map((key) => ({ + locale, + slug: PAGE_SLUGS[key][locale], + })) + ) +} + +const LEGAL_META: Record<'privacy' | 'terms', Record> = { + privacy: { + hu: 'Adatvédelmi tájékoztató - ismerje meg, hogyan kezeljük személyes adatait.', + en: 'Privacy policy — learn how we handle your personal data.', + }, + terms: { + hu: 'Általános Szerződési Feltételek - Ismerje meg a mozdIT Bt. szolgáltatásainak használati feltételeit.', + en: 'Terms of Service — learn about the terms and conditions of mozdIT Bt.’s services.', + }, +} + +export async function generateMetadata({ params }: { params: Promise }): Promise { + const { locale: rawLocale, slug } = await params + if (!isLocale(rawLocale)) return {} + const locale: Locale = rawLocale + const key = resolvePageKey(locale, slug) + if (!key) return {} + + const base = (title: string, description: string, ogDescription = description) => ({ + title: `${title} | ${siteConfig.general.name}`, + description, + openGraph: { + title: `${title} | ${siteConfig.general.name}`, + description: ogDescription, + url: `${siteConfig.general.url}${'/' + locale}/${slug}`, + locale: getOgLocale(locale), + }, + }) + + if (key === 'about') { + const about = await getAboutContent(locale) + return base(about.meta.title, about.meta.description, about.meta.ogDescription) + } + if (key === 'services') { + const services = await getServicesContent(locale) + return base(services.meta.title, services.meta.description, services.meta.ogDescription) + } + if (key === 'contact') { + const contact = await getContactContent(locale) + return base(contact.meta.title, contact.meta.description) + } + if (key === 'privacy') { + const page = await getLegalPage('adatvedelem', locale) + return base(page?.title ?? 'Adatvédelem', LEGAL_META.privacy[locale]) + } + // terms + const page = await getLegalPage('hasznalati-feltetelek', locale) + return base(page?.title ?? 'ÁSZF', LEGAL_META.terms[locale]) +} + +export default async function CatchAllPage({ params }: { params: Promise }) { + const { locale: rawLocale, slug } = await params + if (!isLocale(rawLocale)) notFound() + const locale: Locale = rawLocale + const key = resolvePageKey(locale, slug) + if (!key) notFound() + + if (key === 'about') { + const content = await getAboutContent(locale) + return + } + + if (key === 'services') { + const [content, home, common] = await Promise.all([ + getServicesContent(locale), + getHomeContent(locale), + getCommonContent(locale), + ]) + return ( + + ) + } + + if (key === 'contact') { + const [content, home, common] = await Promise.all([ + getContactContent(locale), + getHomeContent(locale), + getCommonContent(locale), + ]) + return ( + + ) + } + + const page = await getLegalPage(key === 'privacy' ? 'adatvedelem' : 'hasznalati-feltetelek', locale) + if (!page) notFound() + return +} diff --git a/proto/src/app/(frontend)/[locale]/layout.tsx b/proto/src/app/(frontend)/[locale]/layout.tsx new file mode 100644 index 0000000..07447fb --- /dev/null +++ b/proto/src/app/(frontend)/[locale]/layout.tsx @@ -0,0 +1,58 @@ +import { notFound } from 'next/navigation' +import Header from '../../../components/Header' +import Footer from '../../../components/Footer' +import { LOCALES, isLocale, localePath, type Locale } from '@/lib/i18n' +import { getCommonContent, getHomeContent } from '@/lib/payload-content' +import { siteConfig, getMainNavigation, getFooterNavigation, getFooterLegalLinks, getSiteDescription } from '@/config/site' + +export function generateStaticParams() { + return LOCALES.map((locale) => ({ locale })) +} + +export default async function LocaleLayout({ + children, + params, +}: { + children: React.ReactNode + params: Promise<{ locale: string }> +}) { + const { locale: rawLocale } = await params + if (!isLocale(rawLocale)) notFound() + const locale: Locale = rawLocale + + const [common, home] = await Promise.all([ + getCommonContent(locale), + getHomeContent(locale), + ]) + + const isStaging = process.env.NEXT_PUBLIC_DEPLOY_ENV === 'staging' + + return ( + <> + {isStaging && ( +
+ {common.staging.banner} +
+ )} +
+
+ {children} +
+