canina/frontend/application/app/blog/page.tsx
parsa aghaei ab7ed279c8 fix: await params Promise in blog and wiki [slug] pages for Next.js 16
- blog/[slug]/page.tsx: fix params type to Promise and await it
- wiki/[slug]/page.tsx: fix params type to Promise and await it + Fix API port from 4000 to 4001
- blog/page.tsx: fix fallback API URL from port 4000 to 4001
2026-07-11 15:51:29 +03:30

35 lines
1.2 KiB
TypeScript

import BlogPage from "../../components/BlogPage";
import type { Metadata } from 'next';
export const metadata: Metadata = {
title: 'مجله سلامت حیوانات خانگی',
description: 'آخرین مقالات، آموزش‌ها و اخبار علمی در زمینه نگهداری، تغذیه و سلامت سگ و گربه.',
};
async function getBlogs() {
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001';
try {
const res = await fetch(`${apiUrl}/api/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: 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} />;
}