This document describes the new dynamic OG image generation system for Refetch threads.
Refetch now generates dynamic Open Graph (OG) images for each thread page, optimized for 16:9 resolution (1200x630px). These images are automatically generated and include:
- Thread title
- Domain information
- Time since posting
- Reading time (if available)
- Description (truncated to 200 characters)
- Author name
- Comment count
- Upvote count
- Refetch branding
GET /api/og/thread/[id]
Generates a dynamic OG image for a specific thread based on its ID.
Example:
https://refetch.io/api/og/thread/64a1b2c3d4e5f6g7h8i9j0
GET /api/og/test
Generates a test OG image with sample data for development and testing purposes.
Example:
https://refetch.io/api/og/test
@vercel/og- For server-side image generation- Edge runtime for optimal performance
- Resolution: 1200x630px (16:9 aspect ratio)
- Format: PNG (default)
- Font: Inter (system fallback)
- Colors: Refetch brand colors (#4e1cb3 for primary)
Images are generated using data from the fetchPostById function, which returns a NewsItem object containing:
title- Thread titledomain- Source domaindaysAgo- Time since postingdescription- Thread descriptionreadingTime- Estimated reading timeauthor- Author namecountComments- Number of commentscount- Total upvotes
OG images are automatically generated when visiting any thread page. The metadata is dynamically generated in the generateMetadata function.
You can test the OG image generation by visiting:
/api/og/test- Test image with sample data/api/og/thread/[actual-thread-id]- Real thread image
When sharing Refetch threads on social media platforms, the dynamic OG images will automatically be displayed, showing:
- Twitter: Large image cards
- Facebook: Rich link previews
- LinkedIn: Professional link previews
- Other platforms: Standard OG image support
Add the following to your .env.local file:
NEXT_PUBLIC_BASE_URL=https://refetch.ioThis ensures the correct base URL is used for OG image URLs in production.
The OG image design can be customized by editing app/api/og/thread/[id]/route.tsx. The design uses inline styles and follows the same visual language as the post cards.
To include additional thread information in the OG image:
- Ensure the data is available in the
NewsIteminterface - Add the field to the image layout in the API route
- Update the metadata generation if needed
To modify the image dimensions, update the width and height properties in the ImageResponse constructor. Maintain the 16:9 aspect ratio for optimal social media display.
- Edge Runtime: Uses Vercel's edge runtime for fast global delivery
- Caching: Images are generated on-demand and can be cached by CDNs
- Fallbacks: Graceful error handling with fallback images for missing threads
-
Image Not Loading
- Check that
@vercel/ogis properly installed - Verify the edge runtime is supported in your deployment environment
- Check browser console for any JavaScript errors
- Check that
-
Incorrect Data
- Verify the thread ID is valid
- Check that
fetchPostByIdreturns the expected data structure - Ensure all required fields are present in the
NewsIteminterface
-
Styling Issues
- Verify font availability (Inter fallback to system fonts)
- Check color values are valid hex codes
- Ensure dimensions are positive integers
Enable debug logging by checking the browser console and server logs for detailed error information.
Potential improvements for the OG image system:
- Custom themes based on thread categories
- Dynamic color schemes
- Animated elements (GIF support)
- Multiple layout options
- A/B testing for different designs
- Analytics tracking for image generation performance
For issues or questions about the OG image system, please refer to:
- The main Refetch documentation
- GitHub issues for bug reports
- Community discussions for feature requests