Skip to main content
Reggie Pangilinan
HomeBlogAbout
GitHubLinkedIn

© 2026 reggiepangilinan.com All rights reserved.

GitHubLinkedIn
Client-Side QR Code Sharing and Smart Open Graph Cards in…
←Back to Blog

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.

December 2, 2026·Reggie Pangilinan·2 min read
Client-Side QR Code Sharing and Smart Open Graph Cards in Next.js

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 via useSyncExternalStore).

  • 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!

Smart Sharing & Open Graph Pipeline
Smart Sharing & Open Graph Pipeline

✂️ 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 Pangilinan pushes 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: 630

  • fit: '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.

Keep Reading

Related Posts

December 3, 2026

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.

Next.jsTypeScript
December 3, 2026

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.

Next.jsContentful
December 2, 2026

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.

Next.jsSEO
Topics
Next.jsSEOUXContentfulTypeScript

Share this article

Found this helpful? Copy the link or scan the QR code to share it.

←All blog posts