This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
import Link from "next/link";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { notFound } from "next/navigation";
|
||||
import ApplicationClient from "./ApplicationClient";
|
||||
|
||||
// 🔥 IMPORTAMOS LA TUBERÍA MÁGICA
|
||||
import { getLocalizedData } from "@/lib/i18nHelper";
|
||||
|
||||
// --- FUNCIÓN ORIGINAL PARA LEER IMÁGENES LOCALES ---
|
||||
function getApplicationImages(slug: string) {
|
||||
const imagesDir = path.join(process.cwd(), "public", "applications", slug);
|
||||
let blueprints: string[] = [];
|
||||
let machines: string[] = [];
|
||||
let heroImage = "";
|
||||
|
||||
if (fs.existsSync(imagesDir)) {
|
||||
const files = fs.readdirSync(imagesDir).filter(file => /\.(png|jpe?g|webp)$/i.test(file));
|
||||
|
||||
heroImage = files[0] ? `/applications/${slug}/${files[0]}` : "";
|
||||
blueprints = files.filter(f => f.includes("Screenshot") || f.startsWith("P10") || f.includes("blueprint")).slice(0, 3).map(f => `/applications/${slug}/${f}`);
|
||||
machines = files.filter(f => !f.includes("Screenshot") && !f.startsWith("P10") && !f.includes("blueprint")).slice(1, 4).map(f => `/applications/${slug}/${f}`);
|
||||
}
|
||||
|
||||
return { heroImage, blueprints, machines };
|
||||
}
|
||||
|
||||
// GENERACIÓN DE RUTAS ESTÁTICAS DESDE LA BD
|
||||
export async function generateStaticParams() {
|
||||
const apps = await prisma.application.findMany({ select: { slug: true } });
|
||||
return apps.map((app: { slug: string }) => ({ slug: app.slug }));
|
||||
}
|
||||
|
||||
export const revalidate = 60;
|
||||
|
||||
// 🔥 AHORA RECIBIMOS EL LOCALE DESDE LA URL
|
||||
export default async function ApplicationPage({ params }: { params: Promise<{ slug: string, locale: string }> }) {
|
||||
const resolvedParams = await params;
|
||||
const { slug, locale } = resolvedParams;
|
||||
|
||||
// 1. Buscamos la Teoría General de la Aplicación
|
||||
const rawData = await prisma.application.findUnique({
|
||||
where: { slug }
|
||||
});
|
||||
|
||||
if (!rawData) {
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col items-center justify-center bg-[#F5F5F7] dark:bg-[#050505]">
|
||||
<h1 className="text-2xl text-[#86868B] mb-4">Application not found in Database</h1>
|
||||
<Link href={`/${locale}/#applications-deep`} className="text-[#00F0FF] hover:underline">Return Home</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 TRADUCIMOS LA APLICACIÓN PRINCIPAL
|
||||
const data = getLocalizedData(rawData, locale);
|
||||
|
||||
// 2. Buscamos el "Muro de Soluciones" (Casos Reales específicos de esta app)
|
||||
const rawRealCases = await prisma.globalNode.findMany({
|
||||
where: {
|
||||
application: slug,
|
||||
isActive: true,
|
||||
projectOverview: { not: null }
|
||||
},
|
||||
orderBy: { createdAt: 'desc' }
|
||||
});
|
||||
|
||||
// 🔥 TRADUCIMOS TODOS LOS CASOS DE ESTUDIO DEL MURO
|
||||
const realCases = rawRealCases.map((node: any) => getLocalizedData(node, locale));
|
||||
|
||||
// 3. Leemos las imágenes de la carpeta original
|
||||
const images = getApplicationImages(slug);
|
||||
|
||||
// Pasamos TODO al componente cliente interactivo (que ya viene traducido)
|
||||
return <ApplicationClient data={data} realCases={realCases} images={images} />;
|
||||
}
|
||||
Reference in New Issue
Block a user