SERP, Open Graph, and Twitter Card preview generators with React components
Package Exports
@power-seo/preview
@power-seo/preview/react
Readme
@power-seo/preview
Pixel-accurate SERP, Open Graph, and Twitter/X Card preview generators for TypeScript — compute exactly how a page appears in Google search results and social shares without a headless browser or canvas.
@power-seo/preview delivers pixel-width-aware SERP snippet generation, Open Graph image validation, and Twitter/X Card preview data — comparable to what Yoast SEO, Semrush, and Moz Pro show in their browser-based UIs, but as a standalone TypeScript library that runs anywhere. Provide a title, meta description, URL, and optional OG image — get back structured preview data with truncation flags, breadcrumb paths, and image validation results. Run it server-side in a CMS pipeline, client-side in a React editor, or inside a CI content gate. All four generators are fully tree-shakeable.
Zero runtime dependencies — only @power-seo/core as a peer.
Why @power-seo/preview?
Without
With
SERP title truncation
❌ Guesswork (character count)
✅ Pixel-accurate truncation at 580px
SERP description truncation
❌ Unchecked
✅ Pixel-accurate truncation at 920px
OG image validation
❌ Silent drop by Facebook/LinkedIn
✅ Dimension check with pass/fail message
Twitter/X Card preview
❌ Manual spec lookup
✅ summary + summary_large_image with image validation
✅ Next.js, Remix, Node.js, Edge, any JS environment
Features
Pixel-accurate SERP truncation — generateSerpPreview() truncates title at 580px, description at 920px using character-width lookup tables
Site title composition — optional siteTitle field appended as "title - siteTitle" before truncation, matching Google's display format
Google breadcrumb URL — formats https://example.com/blog/my-post as example.com › blog › my-post
Open Graph image validation — generateOgPreview() validates image dimensions against the recommended 1200×630 minimum and reports pass/fail with a message
Twitter/X Card support — generateTwitterPreview() handles summary and summary_large_image card types with per-type image dimension requirements
Low-level truncation primitive — truncateAtPixelWidth() truncates any string at any pixel budget, usable independently of the preview generators
Structured typed output — returns plain data objects ready for any UI renderer; no HTML, no DOM required
React UI components — pre-built SerpPreview, OgPreview, TwitterPreview, and PreviewPanel from the /react subpath
Framework-agnostic — works in Next.js, Remix, Gatsby, Vite, vanilla Node.js, Edge
Full TypeScript support — complete type definitions for all inputs, outputs, and validation results
Tree-shakeable — import only the generators you use; "sideEffects": false
Zero runtime dependencies — pure computation, no canvas, no browser, no external libraries
Comparison
Feature
@power-seo/preview
Yoast SEO
next-seo
react-helmet
seo-analyzer
Pixel-accurate SERP truncation
✅
✅ (browser only)
❌
❌
❌
SERP description truncation
✅
✅ (browser only)
❌
❌
❌
Google breadcrumb URL format
✅
✅
❌
❌
❌
Open Graph image validation
✅
❌
❌
❌
❌
Twitter/X Card preview generation
✅
❌
❌
❌
❌
React preview components
✅
✅
❌
❌
❌
Works outside WordPress
✅
❌
✅
✅
✅
Edge runtime safe
✅
❌
✅
✅
❌
Structured data output (not HTML)
✅
❌
❌
❌
❌
TypeScript-first
✅
❌
Partial
❌
❌
Tree-shakeable
✅
❌
Partial
❌
❌
CI / Node.js usage
✅
❌
❌
❌
✅
Zero runtime dependencies
✅
❌
❌
❌
❌
Installation
npminstall @power-seo/preview
yarnadd @power-seo/preview
pnpmadd @power-seo/preview
Quick Start
import{ generateSerpPreview, generateOgPreview }from'@power-seo/preview';const serp =generateSerpPreview({
title:'How to Add SEO to React Apps',
description:'Learn how to add meta tags, Open Graph, and JSON-LD to any React application.',
url:'https://example.com/blog/react-seo',
siteTitle:'My Blog',// optional — appended as "title - siteTitle"});console.log(serp.title);// 'How to Add SEO to React Apps - My Blog' (truncated at 580px if too long)console.log(serp.displayUrl);// 'example.com › blog › react-seo'console.log(serp.titleTruncated);// falseconst og =generateOgPreview({
title:'React SEO Guide',
description:'Complete SEO for React',
url:'https://example.com/blog/react-seo',
image:{ url:'https://example.com/og.jpg', width:1200, height:630},});console.log(og.image?.valid);// trueconsole.log(og.image?.message);// undefined (dimensions are correct)
Usage
Generating a Google SERP Preview
generateSerpPreview() computes the display title, breadcrumb URL, and description that Google would show, with pixel-accurate truncation flags.
import{ generateSerpPreview }from'@power-seo/preview';const serp =generateSerpPreview({
title:'Next.js SEO Best Practices',
description:'Learn how to optimize your Next.js app for search engines with meta tags and structured data.',
url:'https://example.com/nextjs-seo',
siteTitle:'Dev Blog',// optional});// serp.title → 'Next.js SEO Best Practices - Dev Blog' (possibly truncated)// serp.displayUrl → 'example.com › nextjs-seo'// serp.description → display description (possibly truncated at 920px)// serp.titleTruncated → true | false// serp.titleValidation → ValidationResult from @power-seo/core
Generating an Open Graph Preview
generateOgPreview() validates image dimensions and returns a structured card data object for Facebook, LinkedIn, and other OG-compatible platforms.
import{ generateOgPreview }from'@power-seo/preview';const og =generateOgPreview({
title:'React SEO Guide',
description:'Complete guide to adding SEO in React apps.',
url:'https://example.com/react-seo',
siteName:'Dev Blog',
image:{ url:'https://example.com/og.jpg', width:800, height:400},});// og.image?.valid → false (too small)// og.image?.message → 'Image is 800x400px. Minimum size is 200x200px.'
Generating a Twitter/X Card Preview
generateTwitterPreview() handles both summary and summary_large_image card types, each with different image dimension requirements.
import{ generateTwitterPreview }from'@power-seo/preview';const twitter =generateTwitterPreview({
cardType:'summary_large_image',
title:'React SEO Guide',
description:'Everything you need to add SEO to any React application.',
url:'https://example.com/react-seo',
site:'@myblog',
image:{ url:'https://example.com/twitter.jpg', width:1200, height:628},});// twitter.cardType → 'summary_large_image'// twitter.domain → 'myblog'// twitter.image?.valid → true
Using the Low-Level Truncation Primitive
truncateAtPixelWidth() is a standalone utility — use it to truncate any string at any pixel budget, independent of the SERP generator.
Import from the /react entry point for pre-built preview UI components:
import{ SerpPreview, OgPreview, TwitterPreview, PreviewPanel }from'@power-seo/preview/react';// All-in-one tabbed panel (Google / Facebook / Twitter)functionEditorSidebar(){return(<PreviewPaneltitle="How to Add SEO to React Apps"description="Learn meta tags, Open Graph, and JSON-LD for React."url="https://example.com/blog/react-seo"siteTitle="My Blog"siteName="My Blog"image={{ url:'https://example.com/og.jpg', width:1200, height:630}}twitterCardType="summary_large_image"twitterSite="@myblog"/>);}// Or use individual componentsfunctionSerpCard(){return(<SerpPreviewtitle="How to Add SEO to React Apps"description="Learn meta tags, Open Graph, and JSON-LD for React."url="https://example.com/blog/react-seo"siteTitle="My Blog"/>);}
Inside a CI Content Quality Gate
Block deploys when SERP titles or OG images fail validation:
import{ generateSerpPreview, generateOgPreview }from'@power-seo/preview';const serp =generateSerpPreview({ title, description, url, siteTitle });const og =generateOgPreview({ title, description, url, image });if(serp.titleTruncated){console.error('SERP title exceeds 580px — will be cut off in Google results');
process.exit(1);}if(og.image &&!og.image.valid){console.error('OG image invalid:', og.image.message);
process.exit(1);}
CyberCraft Bangladesh is a Bangladesh-based enterprise-grade software development and Full Stack SEO service provider company specializing in ERP system development, AI-powered SaaS and business applications, full-stack SEO services, custom website development, and scalable eCommerce platforms. We design and develop intelligent, automation-driven SaaS and enterprise solutions that help startups, SMEs, NGOs, educational institutes, and large organizations streamline operations, enhance digital visibility, and accelerate growth through modern cloud-native technologies.