feat: atualizar URLs para octtoengenharia.com.br, adicionar SEO dinâmico em projetos e corrigir WhatsApp button
This commit is contained in:
82
frontend/src/app/[locale]/projetos/[id]/metadata.ts
Normal file
82
frontend/src/app/[locale]/projetos/[id]/metadata.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { Metadata } from 'next';
|
||||
|
||||
interface Project {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string | null;
|
||||
coverImage: string | null;
|
||||
category: string;
|
||||
client: string | null;
|
||||
completionDate: string | null;
|
||||
}
|
||||
|
||||
async function getProject(id: string): Promise<Project | null> {
|
||||
try {
|
||||
const res = await fetch(`https://octtoengenharia.com.br/api/projects/${id}`, {
|
||||
next: { revalidate: 3600 }, // Cache 1 hora
|
||||
});
|
||||
if (res.ok) {
|
||||
return await res.json();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erro ao buscar projeto para metadata:', error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function generateMetadata(
|
||||
{ params }: { params: { id: string; locale: string } },
|
||||
parent: any
|
||||
): Promise<Metadata> {
|
||||
const project = await getProject(params.id);
|
||||
|
||||
if (!project) {
|
||||
return {
|
||||
title: 'Projeto não encontrado',
|
||||
description: 'O projeto que você procura não existe.',
|
||||
};
|
||||
}
|
||||
|
||||
const baseUrl = 'https://octtoengenharia.com.br';
|
||||
const prefix = params.locale === 'pt' ? '' : `/${params.locale}`;
|
||||
const projectUrl = `${baseUrl}${prefix}/projetos/${project.id}`;
|
||||
const description = project.description || `Projeto de ${project.category} da Octto Engenharia${project.client ? ` para ${project.client}` : ''}`;
|
||||
|
||||
const localeMap: Record<string, string> = {
|
||||
pt: 'pt_BR',
|
||||
en: 'en_US',
|
||||
es: 'es_ES',
|
||||
};
|
||||
|
||||
return {
|
||||
title: `${project.title} | Octto Engenharia`,
|
||||
description,
|
||||
keywords: `${project.title}, ${project.category}, engenharia, ${project.client || 'Octto Engenharia'}`,
|
||||
openGraph: {
|
||||
type: 'article',
|
||||
title: project.title,
|
||||
description,
|
||||
url: projectUrl,
|
||||
images: project.coverImage
|
||||
? [
|
||||
{
|
||||
url: project.coverImage,
|
||||
width: 1200,
|
||||
height: 630,
|
||||
alt: project.title,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
locale: localeMap[params.locale] || 'pt_BR',
|
||||
},
|
||||
twitter: {
|
||||
card: 'summary_large_image',
|
||||
title: project.title,
|
||||
description,
|
||||
images: project.coverImage ? [project.coverImage] : [],
|
||||
},
|
||||
alternates: {
|
||||
canonical: projectUrl,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useLocale } from "@/contexts/LocaleContext";
|
||||
export { generateMetadata } from "./metadata";
|
||||
|
||||
interface Project {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user