47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
import BlogPage from "../../components/BlogPage";
|
||
import type { Metadata } from 'next';
|
||
|
||
export const metadata: Metadata = {
|
||
title: "مجله سلامت حیوانات خانگی و مقالات علمی - کنینا ایران",
|
||
description: "آخرین مقالات، آموزشهای دامپزشکی و اخبار علمی روز دنیا در زمینه نگهداری، تغذیه تخصصی و سلامت سگ و گربه.",
|
||
alternates: {
|
||
canonical: "/blog",
|
||
},
|
||
openGraph: {
|
||
title: "مجله سلامت حیوانات خانگی - کنینا ایران",
|
||
description: "آخرین مقالات، آموزشها و اخبار علمی در زمینه نگهداری، تغذیه و سلامت سگ و گربه.",
|
||
url: "https://canina-iran.com/blog",
|
||
siteName: "کنینا ایران",
|
||
locale: "fa_IR",
|
||
type: "website",
|
||
}
|
||
};
|
||
|
||
async function getBlogs() {
|
||
const rawApiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:4001/api';
|
||
const apiBase = rawApiUrl.endsWith('/api') ? rawApiUrl : `${rawApiUrl}/api`;
|
||
try {
|
||
const res = await fetch(`${apiBase}/blogs`, { next: { revalidate: 60 } });
|
||
if (!res.ok) throw new Error('Failed to fetch blogs');
|
||
const data = await res.json();
|
||
return (data.data || data).map((b: Record<string, unknown>) => ({
|
||
id: String(b.id || ''),
|
||
slug: String(b.slug || ''),
|
||
title: String(b.title || ''),
|
||
excerpt: String(b.metaDescription || (typeof b.content === 'string' ? b.content.substring(0, 150).replace(/<[^>]+>/g, '') + '...' : '')),
|
||
category: String(b.category || 'تغذیه و سلامت'),
|
||
date: String(b.createdAt || new Date().toISOString()).split('T')[0],
|
||
readTime: '۵ دقیقه',
|
||
imageUrl: String(b.coverImage || 'https://images.unsplash.com/photo-1548767797-d8c844163c4c?auto=format&fit=crop&q=80&w=800'),
|
||
}));
|
||
} catch (error) {
|
||
console.error(error);
|
||
return [];
|
||
}
|
||
}
|
||
|
||
export default async function Blog() {
|
||
const blogs = await getBlogs();
|
||
return <BlogPage blogs={blogs} />;
|
||
}
|