Skip to main content

Blog Detail Page

The BlogDetail page component renders a full blog post article with metadata, featured image, and formatted content. It fetches posts from WordPress CMS by slug or falls back to static data.

Location

File: pages/BlogDetail.tsx
Route: /blog/:slug

Features

  • Dynamic routing with slug parameter from URL
  • WordPress integration via fetchBlogPosts to find post by slug
  • Static fallback using siteContent.blog.posts when WordPress unavailable
  • SEO optimization with dynamic meta tags
  • Loading state while fetching WordPress data
  • 404 handling for non-existent slugs
  • Responsive layout with featured image, metadata, and content

Route Configuration

Defined in App.tsx:36:
App.tsx
Example URL: https://example.com/blog/que-es-la-mioglobina

Data Flow

1

Extract slug from URL

Uses useParams hook from React Router to get the slug parameter:
2

Fetch WordPress posts

Attempts to fetch all posts from WordPress:
3

Find post by slug

Searches the posts array for a matching slug:
4

Render post or 404

Displays the post if found, otherwise shows “not found” message.

Component Structure

Hero Section

Displays category badge, title, metadata, and featured image:
pages/BlogDetail.tsx

Content Section

Renders HTML content from WordPress using dangerouslySetInnerHTML:
pages/BlogDetail.tsx
Security Note: The component uses dangerouslySetInnerHTML to render WordPress HTML. Ensure your WordPress instance is trusted and sanitizes content properly.

Loading State

pages/BlogDetail.tsx

404 State

pages/BlogDetail.tsx

SEO Integration

Dynamic SEO tags based on post data:
pages/BlogDetail.tsx

Styling

The blog content uses Tailwind Typography plugin classes:
  • prose - Base typography styles
  • prose-invert - Light text on dark background
  • prose-lg - Larger font sizes for readability
  • max-w-none - Remove default max-width constraint
These classes are configured via CDN in index.html:35:
index.html

WordPress vs Static Data

The component gracefully handles both data sources:

Usage Example

Navigation from Blog listing page:
pages/Blog.tsx

Back Navigation

The page includes a back link to the blog listing:
pages/BlogDetail.tsx