This implementation ensures that blog pages display the blog's thumbnail in social media previews (Open Graph and Twitter Cards) when shared on platforms like Facebook, Twitter, LinkedIn, etc.
Blog posts are stored with the following structure:
{
blogs: {
title: "Blog Title",
content: "Blog content...",
thumbnail: "https://example.com/thumbnail.jpg", // Blog thumbnail URL
category: "Technology",
tags: ["programming", "web development"]
},
thumbnail: "https://example.com/thumbnail.jpg", // Alternative thumbnail path
date: "2024-01-01",
// ... other fields
}The system extracts the thumbnail from multiple possible locations:
const thumbnail = getBlogs?.blogs?.thumbnail || getBlogs?.thumbnail || '';The SEOComponent receives the blog data and generates appropriate meta tags:
<SEOComponent
type="blog"
blog={safeBlog}
currentUrl={window.location.href}
/>The generateBlogSEOTags function creates comprehensive meta tags:
<meta property="og:type" content="article">
<meta property="og:title" content="Blog Title">
<meta property="og:description" content="Blog description...">
<meta property="og:image" content="https://phcoder05.vercel.app/thumbnail.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="Blog Title - Blog Post by Pankaj Hadole"><meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Blog Title">
<meta name="twitter:description" content="Blog description...">
<meta name="twitter:image" content="https://phcoder05.vercel.app/thumbnail.jpg">
<meta name="twitter:image:alt" content="Blog Title - Blog Post by Pankaj Hadole">The optimizeThumbnailForSocial function ensures thumbnails are properly formatted:
- Converts relative URLs to absolute URLs
- Validates URL format
- Provides fallback to default logo
- Ensures proper domain prefixing
- Automatically extracts thumbnail from blog data
- Handles multiple thumbnail field locations
- Provides fallback to default logo
- Optimized for Facebook, Twitter, LinkedIn
- Proper image dimensions (1200x630)
- Descriptive alt text for accessibility
- Ensures absolute URLs for social media
- Validates URL format
- Handles relative and absolute paths
- Development mode debug panel
- Meta tag validation
- Social media preview test links
- Console logging for troubleshooting
When in development mode, blog pages show a debug panel with:
- Current thumbnail URL
- Meta tag validation status
- Links to test social media previews
- Facebook: https://developers.facebook.com/tools/debug/
- Twitter: https://cards-dev.twitter.com/validator
- LinkedIn: https://www.linkedin.com/post-inspector/
- Google: https://search.google.com/test/rich-results
- Visit any blog page
- Open browser developer tools
- Check the
<head>section for meta tags - Verify
og:imageandtwitter:imagecontain the blog thumbnail
src/pages/blogInfo/BlogInfo.jsx- Blog page componentsrc/components/SEOComponent.jsx- SEO meta tag componentsrc/utils/seoUtils.js- SEO utilities and thumbnail optimization
generateBlogSEOTags()- Generates blog-specific SEO tagsoptimizeThumbnailForSocial()- Optimizes thumbnail URLsvalidateMetaTags()- Validates meta tag presencegenerateSocialPreviewTestUrls()- Generates test URLs
- Recommended size: 1200x630 pixels
- Format: JPG, PNG, or WebP
- File size: Under 1MB
- Aspect ratio: 1.91:1 (Facebook optimal)
- Must be absolute URLs (https://...)
- Must be publicly accessible
- Should be served over HTTPS
- Should have proper CORS headers
- Use blog thumbnail if available
- Fall back to default logo
- Ensure URL is absolute
- Validate URL format
- Check if thumbnail URL is accessible
- Verify URL is absolute (starts with http/https)
- Check browser console for errors
- Use debug panel to validate meta tags
- Clear social media cache:
- Facebook: Use debugger tool
- Twitter: Use validator tool
- LinkedIn: Use post inspector
- Wait 24-48 hours for cache refresh
- Check if URL is publicly accessible
- Verify
SEOComponentis rendered - Check if blog data is loaded
- Validate thumbnail extraction logic
- Check browser console for errors
// Check meta tags in browser console
validateMetaTags()
// Test social media preview URLs
generateSocialPreviewTestUrls(window.location.href)- Automatic thumbnail generation from blog content
- Multiple thumbnail sizes for different platforms
- Image optimization and compression
- CDN integration for faster loading
- Analytics for social media sharing
- Lazy loading for thumbnails
- WebP format support
- Responsive image sizes
- Cache optimization
For issues or questions about the dynamic thumbnail implementation:
- Check the debug panel in development mode
- Review browser console for errors
- Test with social media validation tools
- Verify blog data structure and thumbnail URLs