Client-Side QR Code Sharing and Smart Open Graph Cards in Next.js
Making articles effortless to share in person and crisp when pasted into LinkedIn, X, or Slack—with zero extra design work.

Sharing a blog post shouldn't feel like an afterthought—whether someone is copying a URL into Slack, sharing from their phone, or scanning a slide at a meetup. 📱
Instead of dropping in heavy third-party social share widgets (which usually come with tracking scripts and clunky styling), I built two small pieces into reggiepangilinan.com: a lightweight PostShareBar and a smart metadata pipeline in src/lib/seo.ts.
📲 1. PostShareBar: Copy, Native Share & Instant QR Codes
Every blog post renders PostShareBar in two places—a compact bar next to the post metadata at the top, and a fuller prompt at the bottom of the article.
It gives readers three zero-bloat actions:
One-click Copy Link: Copies the canonical URL with instant checkmark feedback.
Native Web Share API: Uses
navigator.share()on mobile and supported browsers (checked safely without hydration mismatches viauseSyncExternalStore).Client-Side QR Code Generator + PNG Download: Generates a high-contrast QR code right in the browser using
qrcode, complete with a one-click PNG download—super handy if I ever want to drop a link to a post onto a presentation slide!

✂️ 2. Word-Boundary SEO Truncation
Nothing makes a link preview look sloppy faster than a title or description chopped right in the middle of a word.
In src/lib/seo.ts, truncateAtWord() trims titles and descriptions cleanly at word boundaries and strips trailing punctuation before appending …:
Page / OG / Twitter titles: kept within 60 characters (falling back cleanly if adding
| Reggie Pangilinanpushes it over).Meta descriptions: trimmed cleanly to 155 characters.
Social card descriptions: trimmed to 125 characters so LinkedIn, X, and Slack previews stay punchy.
🖼️ 3. Automatic 1200×630 Open Graph Social Cards
Exporting a custom 1200×630 social thumbnail in Figma for every single blog post is the kind of friction that makes you stop writing. 😅
Instead, getOgImageUrl() in src/app/blog/[slug]/page.tsx passes the post's Contentful featured image through optimizeContentfulImage() with exact Open Graph parameters:
width: 1200,height: 630fit: 'fill',focus: 'center'format: 'jpg',quality: 85(progressive JPEG for universal social crawler compatibility)
And on Netlify PR deploy previews, getMetadataAssetBaseUrl() in src/lib/seo.ts automatically uses DEPLOY_PRIME_URL so you can validate OG tags and social cards before merging to main.
✨ Wrapping Up
Small polish details compound quickly: zero-tracker sharing with built-in QR codes, clean word-boundary titles, and automated 1200×630 social cards mean every post looks intentional the second someone shares the link.
You can check out PostShareBar.tsx and src/lib/seo.ts in the public repo on GitHub.
Related Posts
Adding AI-Powered Blog Search with Google Gemini in Next.js
How we added an intelligent, Gemini-powered search bar to a Next.js + Contentful blog—covering AI basics for non-specialists, why hybrid search beat Google Search Grounding and Vertex AI Search, real-world free-tier traffic estimates, and built-in cost guardrails.
Swiss Design Meets Punk Rock: How I Built an Automated Hero Poster System for My Blog
A plain-English look at the HTML/SVG poster generator behind my blog hero images, a quick intro to the Swiss International Style and punk-zine energy that inspired it, and how every poster flows from Git to Contentful.
Generative Engine Optimization (GEO) in Next.js 16: llms.txt, RSS, JSON-LD & Crawler Access
A plain-English primer on Generative Engine Optimization (GEO) plus six concrete Next.js 16 upgrades: dynamic /llms.txt, /rss.xml, Person & WebSite JSON-LD, explicit AI bot rules, and non-JS visibility.