Files
Spanglish/frontend/src/app/(public)/legal/[slug]/page.tsx
T
Michilis a8b72b47b1 fix(legal): show legal pages in site language with bidirectional toggle
Wire legal pages to LanguageContext, pass locale on footer/booking links,
translate layout chrome, and restore SSR content when switching back to English.
2026-06-04 22:51:32 +00:00

79 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { notFound } from 'next/navigation';
import { Metadata } from 'next';
import { getLegalPageAsync, getAllLegalSlugs } from '@/lib/legal';
import LegalPageLayout from '@/components/layout/LegalPageLayout';
interface PageProps {
params: Promise<{ slug: string }>;
searchParams: Promise<{ locale?: string }>;
}
// Generate static params for all legal pages
export async function generateStaticParams() {
const slugs = getAllLegalSlugs();
return slugs.map((slug) => ({ slug }));
}
// Enable dynamic rendering to always fetch fresh content from DB
export const dynamic = 'force-dynamic';
export const revalidate = 60; // Revalidate every 60 seconds
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://spanglish.com.py';
// Validate and normalize locale
function getValidLocale(locale?: string): 'en' | 'es' {
if (locale === 'es') return 'es';
return 'en'; // Default to English
}
// Generate metadata for SEO
export async function generateMetadata({ params, searchParams }: PageProps): Promise<Metadata> {
const resolvedParams = await params;
const resolvedSearchParams = await searchParams;
const locale = getValidLocale(resolvedSearchParams.locale);
const legalPage = await getLegalPageAsync(resolvedParams.slug, locale);
if (!legalPage) {
return {
title: 'Not Found',
};
}
return {
title: `${legalPage.title} Spanglish`,
description: `${legalPage.title} for Spanglish language exchange events in Asunción, Paraguay.`,
robots: {
index: true,
follow: true,
},
alternates: {
canonical: `${siteUrl}/legal/${resolvedParams.slug}`,
languages: {
'en': `${siteUrl}/legal/${resolvedParams.slug}`,
'es': `${siteUrl}/legal/${resolvedParams.slug}?locale=es`,
},
},
};
}
export default async function LegalPage({ params, searchParams }: PageProps) {
const resolvedParams = await params;
const resolvedSearchParams = await searchParams;
const locale = getValidLocale(resolvedSearchParams.locale);
const legalPage = await getLegalPageAsync(resolvedParams.slug, locale);
if (!legalPage) {
notFound();
}
return (
<LegalPageLayout
slug={resolvedParams.slug}
initialLocale={locale}
title={legalPage.title}
content={legalPage.content}
lastUpdated={legalPage.lastUpdated}
/>
);
}