import React, { useEffect, useState } from 'react'; import { useParams, Link } from 'react-router-dom'; import { wpApi } from '../api/wordpress'; // Helper to handle raw markdown formatting if present const formatContent = (htmlContent) => { if (!htmlContent) return ''; // Replace **text** with text (Basic bold support) return htmlContent.replace(/\*\*(.*?)\*\*/g, '$1'); }; const NewsDetail = () => { const { slug } = useParams(); const [post, setPost] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchPost = async () => { try { setLoading(true); const data = await wpApi.getPostBySlug(slug); if (!data) { throw new Error('Post not found'); } setPost(data); } catch (err) { setError(err); } finally { setLoading(false); } }; if (slug) { fetchPost(); } }, [slug]); if (loading) { return (
); } if (error || !post) { return (

Post Not Found

The article you are looking for does not exist or has been removed.

← Back to News
); } const featuredImage = post._embedded?.['wp:featuredmedia']?.[0]?.source_url; const authorName = post._embedded?.author?.[0]?.name || 'Admin'; const date = new Date(post.date).toLocaleDateString(); return (
{/* Header Section */}
{date} {authorName}

{/* Featured Image */} {featuredImage && (
{post.title.rendered}
)} {/* Content */}
{/* Footer / Navigation */}
); }; export default NewsDetail;