import React from 'react'; import { Link, useParams } from 'react-router-dom'; import { ArrowLeftIcon, ChevronLeftIcon, ClockIcon } from 'lucide-react'; import { renderToHTMLString } from '@tiptap/static-renderer'; import { Reveal } from '../components/Reveal'; import { ButtonLink } from '../components/Button'; import { ArticleCard } from '../components/ArticleCard'; import { Newsletter } from '../components/home/Newsletter'; import { useSite } from '../api'; import { applySeo } from '../seo'; import { useEffect } from 'react'; import { ARTICLE_EXTENSIONS } from '../components/admin/ArticleEditor'; import type { Article } from '../data/site'; /** بدنه مقاله را به HTML تبدیل میکند — سند TipTap جدید یا پاراگرافهای قدیمی */ function renderBody(article: Article): { html: string | null; legacy: string[] } { const body = article.body as unknown; if (Array.isArray(body)) return { html: null, legacy: body }; if (body && typeof body === 'object' && (body as { type?: string }).type === 'doc') { try { return { html: renderToHTMLString({ extensions: ARTICLE_EXTENSIONS, content: body as never }), legacy: [], }; } catch { return { html: null, legacy: [] }; } } return { html: null, legacy: [] }; } export function ArticleDetail() { const { slug } = useParams<{slug: string;}>(); const { articles, brand } = useSite(); const article = articles.find((a) => a.slug === slug); // عنوان تب، توضیح متا، OG و JSON-LD از خود مقاله useEffect(() => { if (!article) return; applySeo({ title: `${article.title} | ${brand}`, description: article.excerpt, path: `/blog/${article.slug}`, image: article.image, type: 'article', jsonLd: { '@context': 'https://schema.org', '@type': 'Article', headline: article.title, description: article.excerpt, image: article.image ? new URL(article.image, window.location.origin).href : undefined, inLanguage: 'fa', author: { '@type': 'Organization', name: brand }, publisher: { '@type': 'Organization', name: brand }, mainEntityOfPage: new URL(`/blog/${article.slug}`, window.location.origin).href, }, }); }, [article?.id]); if (!article) { return ( این مقاله پیدا نشد فهرست کامل مقالات وبلاگ را ببینید. بازگشت به وبلاگ ); } const { html, legacy } = renderBody(article); const related = articles.filter((a) => a.slug !== article.slug && a.status !== 'draft').slice(0, 3); return ( <> صفحه اصلی وبلاگ {article.category} {article.title} {article.date} {article.read} {article.excerpt} {html ? ( ) : ( legacy.map((paragraph, i) => {paragraph} ) )} مقالات مرتبط {related.map((item, i) => )} >); }
فهرست کامل مقالات وبلاگ را ببینید.
{article.excerpt}
{paragraph}