34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import BlogPage from "../../components/BlogPage";
|
|
import type { Metadata } from 'next';
|
|
|
|
export const metadata: Metadata = {
|
|
title: 'مجله سلامت حیوانات خانگی',
|
|
description: 'آخرین مقالات، آموزشها و اخبار علمی در زمینه نگهداری، تغذیه و سلامت سگ و گربه.',
|
|
};
|
|
|
|
async function getBlogs() {
|
|
try {
|
|
const res = await fetch('http://localhost:4001/api/blogs', { next: { revalidate: 60 } });
|
|
if (!res.ok) throw new Error('Failed to fetch blogs');
|
|
const data = await res.json();
|
|
return data.map((b: any) => ({
|
|
id: b.id,
|
|
slug: b.slug,
|
|
title: b.title,
|
|
excerpt: b.metaDescription || b.content.substring(0, 150).replace(/<[^>]+>/g, '') + '...',
|
|
image: b.imageUrl,
|
|
date: new Date(b.createdAt).toLocaleDateString('fa-IR'),
|
|
author: b.author ? `${b.author.firstName} ${b.author.lastName}` : 'نویسنده کانینو',
|
|
content: b.content
|
|
}));
|
|
} catch (error) {
|
|
console.error(error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export default async function Blog() {
|
|
const blogs = await getBlogs();
|
|
return <BlogPage blogs={blogs} />;
|
|
}
|