Skip to main content

Blog Page Component

The Blog page (pages/Blog.tsx) displays a grid of blog posts fetched from a WordPress CMS with fallback to static data.

Purpose

The Blog listing page:
  • Displays all available blog posts in a card grid layout
  • Fetches dynamic content from WordPress CMS
  • Provides fallback to static data if WordPress is unavailable
  • Links to individual blog post detail pages
  • Shows loading states during data fetch

Data Sources

WordPress CMS (Primary)

Blog posts are fetched from WordPress REST API:
Location: pages/Blog.tsx:14-21

WordPress API Details

Location: lib/wordpress.ts:69-80

Static Fallback Data

If WordPress fetch fails, falls back to:

BlogPost Data Structure

Location: types.ts:8-17

Page Structure

Hero Section

Simple centered title and description:
Location: pages/Blog.tsx:32-37

Loading State

Skeleton cards displayed while fetching:
Location: pages/Blog.tsx:39-52 Features:
  • Pulse animation
  • Skeleton layout matches actual card
  • Shows 3 placeholder cards

Blog Posts Grid

Responsive grid of blog post cards:
Location: pages/Blog.tsx:54-80

Components Used

GlassCard

Props Used:
  • hoverEffect={true} - Enable hover animations
  • className - Removes default padding, enables flexbox

SEO Component

State Management

State Flow:
  1. Initial state: Static posts, loading = true
  2. useEffect triggers: Fetch WordPress posts
  3. On success: Update posts, set loading = false
  4. On error: Keep static posts, set loading = false

Data Fetching Flow

1

Component Mounts

Initial render with static fallback posts and loading state = true
2

useEffect Executes

Calls fetchBlogPosts() from WordPress API
3

API Response

  • Success: Update posts state with WordPress data
  • Error: Keep fallback data, log warning to console
4

Finally Block

Set loading = false, triggering re-render with actual content

WordPress Data Mapping

WordPress posts are transformed to match the BlogPost interface:
Location: lib/wordpress.ts:33-51 Transformations:
  • HTML stripping for title and excerpt
  • Date formatting to Spanish locale
  • Featured image extraction from embedded data
  • Category extraction from taxonomy

Routing

Blog Listing

Individual Post

Example: /blog/nuevas-tendencias-empaques-2024

Responsive Grid Layout

Single column, stacked cards

Card Hover Effects

Text Truncation

Excerpts are limited to 3 lines:
This Tailwind utility ensures consistent card heights.

Error Handling

Errors are caught silently and logged to console. The application continues to function with fallback static data.

Styling Patterns

Category Badge

Gradient Overlays

No gradient overlays used in blog listing (simple, clean design).

Glassmorphism

Code Example

Performance Considerations

  • Posts fetched once on component mount
  • Loading state prevents layout shift
  • Images loaded lazily by browser
  • Fallback data ensures instant initial render
  • Home Page - Shows 3 most recent posts
  • Blog Detail Page - Individual post view (linked from cards)
  • WordPress CMS - Content management system