canina/frontend/application/app/layout.tsx
parsa aghaei 8d1b786a24
All checks were successful
Deploy Canina / deploy (push) Successful in 1m50s
chore(brand): rename all Persian occurrences of کانینا to کنینا across the project
2026-08-16 16:40:08 +03:30

131 lines
3.9 KiB
TypeScript

import type { Metadata } from 'next';
import './globals.css';
import ClientLayout from './ClientLayout';
export async function generateMetadata(): Promise<Metadata> {
let seoSettings: {
defaultMetaTitle?: string;
defaultMetaDescription?: string;
keywords?: string | string[];
canonicalBaseUrl?: string;
ogImageUrl?: string;
} | null = null;
try {
const apiBase = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001/api';
const res = await fetch(`${apiBase}/settings/seo`, { next: { revalidate: 60 } });
if (res.ok) {
seoSettings = await res.json();
}
} catch (err) {
console.error('[SEO] Error fetching dynamic SEO settings:', err);
}
const siteUrl = seoSettings?.canonicalBaseUrl || process.env.NEXT_PUBLIC_SITE_URL || 'https://canina-iran.com';
const titleDefault = seoSettings?.defaultMetaTitle || 'کنینا ایران - مکمل‌های درمانی حیوانات خانگی با گرید دارویی اختصاصی';
const descriptionDefault = seoSettings?.defaultMetaDescription || 'تدارک هوشمندانه سلامت برای همراهان وفادار شما. کنینا ایران واردکننده انحصاری مکمل‌های درمانی با گرید دارویی اختصاصی از آلمان.';
let keywordsList: string[] = ['مکمل حیوانات خانگی', 'مکمل سگ', 'مکمل گربه', 'کنینا', 'داروی حیوانات', 'Canina Iran'];
if (seoSettings?.keywords) {
if (Array.isArray(seoSettings.keywords)) {
keywordsList = seoSettings.keywords;
} else if (typeof seoSettings.keywords === 'string') {
keywordsList = seoSettings.keywords.split(',').map(k => k.trim());
}
}
const ogImg = seoSettings?.ogImageUrl || '/assets/images/regenerated_image_1779109861747.png';
return {
metadataBase: new URL(siteUrl),
title: {
template: '%s | کنینا ایران',
default: titleDefault,
},
description: descriptionDefault,
keywords: keywordsList,
authors: [{ name: 'Canina Iran' }],
creator: 'Canina Iran',
publisher: 'Canina Iran',
alternates: {
canonical: '/',
},
formatDetection: {
email: false,
address: false,
telephone: false,
},
openGraph: {
title: titleDefault,
description: descriptionDefault,
url: siteUrl,
siteName: 'کنینا ایران',
locale: 'fa_IR',
type: 'website',
images: [
{
url: ogImg,
width: 1200,
height: 630,
alt: titleDefault,
},
],
},
twitter: {
card: 'summary_large_image',
title: titleDefault,
description: descriptionDefault,
images: [ogImg],
},
robots: {
index: true,
follow: true,
googleBot: {
index: true,
follow: true,
'max-video-preview': -1,
'max-image-preview': 'large',
'max-snippet': -1,
},
},
};
}
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const jsonLd = {
'@context': 'https://schema.org',
'@type': 'Organization',
name: 'کنینا ایران',
url: 'https://canina-iran.com',
logo: 'https://canina.de/media/fb/d5/47/1683116813/Logo.png',
contactPoint: {
'@type': 'ContactPoint',
telephone: '+98-21-88884444',
contactType: 'customer service',
email: 'info@canina-iran.com',
areaServed: 'IR',
availableLanguage: 'Persian'
}
};
const safeJsonLd = JSON.stringify(jsonLd).replace(/</g, '\\u003c');
return (
<html lang="fa" dir="rtl" suppressHydrationWarning>
<body className="min-h-screen bg-medical-gray-50 font-sans" suppressHydrationWarning>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: safeJsonLd }}
/>
<ClientLayout>
{children}
</ClientLayout>
</body>
</html>
);
}