import type { Metadata } from "next"; import Link from "next/link"; import { getPosts, getCategories } from "@/lib/wp-api"; import { BlogPostCard } from "@/components/blog-post-card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { ChevronRight, ChevronLeft } from "lucide-react"; const PER_PAGE = 9; export const metadata: Metadata = { title: "بلاگ", description: "مقالات و مطالب فیپ در زمینه یکپارچه‌سازی، اتوماسیون و بهره‌وری سازمانی.", }; interface BlogPageProps { searchParams: Promise<{ search?: string; category?: string; page?: string }>; } export default async function BlogPage({ searchParams }: BlogPageProps) { const params = await searchParams; const search = params.search ?? ""; const categoryId = params.category ? parseInt(params.category, 10) : undefined; const page = Math.max(1, parseInt(params.page ?? "1", 10) || 1); let postsResult; let categories: Awaited> = []; try { [postsResult, categories] = await Promise.all([ getPosts({ page, perPage: PER_PAGE, search: search || undefined, categoryId: Number.isFinite(categoryId) ? categoryId : undefined, }), getCategories(), ]); } catch (e) { console.log(e) return (

بلاگ

در حال حاضر امکان بارگذاری مطالب وجود ندارد. لطفاً بعداً تلاش کنید.

); } const { posts, total, totalPages } = postsResult; const hasFilters = search || categoryId; function buildQuery(updates: { search?: string; category?: string; page?: number }) { const q = new URLSearchParams(); if (updates.search !== undefined && updates.search !== "") q.set("search", updates.search); if (updates.category !== undefined && updates.category !== "") q.set("category", updates.category); if (updates.page !== undefined && updates.page > 1) q.set("page", String(updates.page)); const s = q.toString(); return s ? `?${s}` : ""; } return ( <> {/* Hero + search & filters in one section */}

بلاگ

مقالات و مطالب فیپ در زمینه یکپارچه‌سازی، اتوماسیون و بهره‌وری سازمانی.

{hasFilters && ( )}
{categories.length > 0 && (
همه {categories.map((cat) => ( {cat.name} ))}
)}
{posts.length === 0 ? (

مطلبی یافت نشد.

) : ( <>
    {posts.map((post) => (
  • ))}
{totalPages > 1 && ( )} )}
); }