Skip to content

fix(og): PNG fallback for non-city routes and robust font-weight parsing - #139

Merged
yakew7 merged 1 commit into
mainfrom
fix/122-og-review-fixes
Aug 21, 2026
Merged

fix(og): PNG fallback for non-city routes and robust font-weight parsing#139
yakew7 merged 1 commit into
mainfrom
fix/122-og-review-fixes

Conversation

@shauryagangrade

Copy link
Copy Markdown
Member

Follow-up fixes from reviewing the #122 implementation (PR #138):

Changes

  1. Root OG fallback → PNG (src/app/layout.tsx:25)

    • SVG og:image is rejected by Facebook, X, WhatsApp, iMessage — never unfurls outside the site.
    • Switched to existing /brand/og.png (924×540). A proper 1200×630 export can follow in a separate PR.
  2. Centralized city lookup (src/lib/city-pages.ts, src/app/city/[slug]/page.tsx, src/app/city/[slug]/opengraph-image.tsx)

    • New findCityPage(places, rawSlug) helper handles percent-decoding + dataset lookup.
    • Eliminates duplicated decodeSlug + cityPages().find() in both the city page and its OG image route.
  3. Robust font-weight loading (src/app/city/[slug]/opengraph-image.tsx:39-71)

    • Old code assumed Google's CSS returned exactly 2 TTF blocks in order [400, 700] and mapped by array index.
    • New code parses font-weight: from each @font-face block, carries weight with the font data, and dedupes by weight.
    • A changed block count/order can no longer silently mislabel weights (which caused bold text to render regular).

Verification

  • ✅ 91/91 unit tests pass (incl. 4 ogCitySummary tests)
  • ✅ ESLint clean on touched files
  • next build succeeds: 217 distinct per-city 1200×630 PNGs prerendered
  • /about now emits og:image = /brand/og.png; city pages emit their own image

Note on fallback dimensions
The existing public/brand/og.png is 924×540 (1.71:1) vs the OG standard 1200×630 (1.91:1). Facebook/X accept it but may crop slightly. A follow-up to regenerate at 1200×630 with brand fonts embedded would be ideal; this PR uses what's available to unblock unfurls today.

Closes the outstanding follow-ups from the review of #138 (which closed #122).

- layout.tsx: switch default OG image from og.svg to og.png.
  SVG og:image is rejected by Facebook, X, WhatsApp, iMessage —
  never unfurls outside the site. The existing og.png (924x540)
  becomes the fallback; a proper 1200x630 export can follow.

- city-pages.ts: add findCityPage() to centralize slug decoding
  and lookup, removing duplicated decodeSlug logic from the city
  page and its OG image route.

- opengraph-image.tsx: parse font-weight from each @font-face
  block instead of assuming array index [0]=400, [1]=700.
  Now weight is explicit per font; misordered/changed Google
  CSS can no longer silently swap weights. Also dedupes
  multiple blocks per weight.

Closes #122 follow-ups from review of #138.
@vercel

vercel Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
study-map Ready Ready Preview Aug 21, 2026 4:58am

@yakew7
yakew7 merged commit a21f1ae into main Aug 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate per-city Open Graph images

2 participants