feat: enhance blog functionality with new components and styles

- Added styles for WordPress table and button blocks in globals.css.
- Updated layout.tsx to include a favicon.
- Improved blog page layout and search functionality, including new search and filter icons.
- Implemented related posts feature in blog post pages with new BlogBlockquote and BlogPullquote components.
- Enhanced blog card display with a new variant for smaller cards.
- Updated blog collapse sections for better user interaction.
- Added new utility functions for extracting block data from WordPress content.
This commit is contained in:
2026-02-05 17:58:28 +03:30
parent bfb967fb43
commit aa6f3c9b35
13 changed files with 386 additions and 69 deletions
+33 -5
View File
@@ -2,14 +2,18 @@ import type { Metadata } from "next";
import Link from "next/link";
import Image from "next/image";
import { notFound } from "next/navigation";
import { getPostBySlug, getFeaturedImageUrl } from "@/lib/wp-api";
import { getPostBySlug, getFeaturedImageUrl, getRelatedPosts } from "@/lib/wp-api";
import { formatDateShamsi } from "@/lib/format-date";
import { ChevronRight } from "lucide-react";
import type { CollapseBlockPayload, BlockquoteBlockPayload } from "@/lib/blog-blocks";
import { parseContentHeadings, getReadingTimeMinutes } from "@/lib/blog-utils";
import { BlogToc } from "@/components/blog-toc";
import { BlogPostMeta } from "@/components/blog-post-meta";
import { BlogCollapseSection } from "@/components/blog-collapse-section";
import { BlogBlockquote } from "@/components/blog-blockquote";
import { BlogPullquote } from "@/components/blog-pullquote";
import { ScrollToTop } from "@/components/scroll-to-top";
import { BlogPostCard } from "@/components/blog-post-card";
interface BlogPostPageProps {
params: Promise<{ slug: string }>;
@@ -39,6 +43,13 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
}
if (!post) notFound();
let relatedPosts: Awaited<ReturnType<typeof getRelatedPosts>> = [];
try {
relatedPosts = await getRelatedPosts(post.id, post.categories ?? [], 3);
} catch {
// show no related section on API error
}
const date = post.date ? formatDateShamsi(post.date) : null;
const modifiedDate = post.modified
? formatDateShamsi(post.modified)
@@ -57,8 +68,8 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
<>
{/* تصویر شاخص تمام‌عرض بالای صفحه */}
{thumbnailUrl && (
<div className="pt-28 md:pt-36">
<div className="relative w-full aspect-[21/5] min-h-[10rem] md:min-h-[10rem] bg-muted">
<div className="pt-10 md:pt-24">
<div className="relative container mx-auto max-w-6xl rounded-xl overflow-hidden shadow-sm w-full aspect-[5/2] min-h-[10rem] md:min-h-[10rem] bg-muted">
<Image
src={thumbnailUrl}
alt={altText}
@@ -114,11 +125,12 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
) : seg.blockType === "collapse" ? (
<BlogCollapseSection
key={i}
section={seg.payload}
section={seg.payload as CollapseBlockPayload}
idPrefix={`blog-${slug}-${i}`}
/>
) : seg.blockType === "blockquote" ? (
<BlogBlockquote key={i} payload={seg.payload as BlockquoteBlockPayload} />
) : (
/* سایر بلاک‌ها (blockquote, code, ...) بعداً با کامپوننت خودشان رندر می‌شوند */
null
)
)}
@@ -127,6 +139,22 @@ export default async function BlogPostPage({ params }: BlogPostPageProps) {
</div>
</div>
</section>
{relatedPosts.length > 0 && (
<section className="bg-muted border-t border-b">
<div className="mx-auto max-w-6xl p-4">
<h2 className="text-xl text-center mb-6 md:mb-8">
مقالات مرتبط
</h2>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{relatedPosts.map((p) => (
<BlogPostCard key={p.id} post={p} variant="tiny" />
))}
</div>
</div>
</section>
)}
<ScrollToTop />
</>
);