Skip to content

Optimize OG images: raw cover / shared card, no per-post generation - #22

Merged
HumbleBee14 merged 8 commits into
mainfrom
feature/og-build-optimization
Jul 14, 2026
Merged

Optimize OG images: raw cover / shared card, no per-post generation#22
HumbleBee14 merged 8 commits into
mainfrom
feature/og-build-optimization

Conversation

@HumbleBee14

@HumbleBee14 HumbleBee14 commented Jul 14, 2026

Copy link
Copy Markdown
Member

What this does

Removes default per-post OG image generation so build time stays flat as the blog grows — keeping the PR preview link fast and staying under Cloudflare Pages' 20k-file-per-deploy cap. Adds an opt-in for the fancy designed card when you want it.

og:image behavior

  • Cover + ogCard: true → generated 1200×630 card (post title over the cover). Renders at build only for these opted-in posts.
  • Cover, no opt-in → the raw cover (no generation; file already ships).
  • No cover → the single prebuilt /og-default.png (built once, reused by all).

The opt-in checkbox (env-gated)

  • Shows a short "Designed share card" checkbox under a cover in /write, with a hover ⓘ explaining it.
  • Gated by PUBLIC_OG_CARD_OPTIN (off by default) so you control it centrally — set it to true to expose the checkbox; leave unset to hide it entirely.
  • Writes ogCard: true to frontmatter; round-trips via .write-source.json.

Also

  • Adds article:author meta (fixes "No author found" in LinkedIn/other inspectors).

Why

og:image is just a URL in the page <head> — it never needs per-post generation. Default = zero cost; the designed card is generated only for the handful that ask for it.

Keeps build time flat regardless of post count (no render or file per post, so
PR preview links aren't delayed and we stay well under Cloudflare's 20k-file
deploy cap):
- Cover posts share the raw cover as og:image; others share the single prebuilt
  /og-default.png
- Per-post composite OG endpoint preserved but disabled (getStaticPaths returns
  []); documented how to re-enable, ideally with edge caching
- Add article:author meta (fixes 'No author found' in link inspectors)
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploying mlsystems with  Cloudflare Pages  Cloudflare Pages

Latest commit: 199c610
Status: ✅  Deploy successful!
Preview URL: https://12958726.mlsystems.pages.dev
Branch Preview URL: https://feature-og-build-optimizatio.mlsystems.pages.dev

View logs

@github-actions

Copy link
Copy Markdown

- New ogCard frontmatter flag: when set (with a cover), the post renders a
  generated 1200x630 card (title over cover); otherwise raw cover / shared card
- Per-post OG generation now runs ONLY for opted-in posts, so build stays flat
- Checkbox shows under a cover in /write, gated by PUBLIC_OG_CARD_OPTIN (off by
  default) so it can be toggled centrally; short label + hover info tooltip
- Round-trips via the .write-source.json sidecar like other meta
- Editor cover preview is now a 1200x630 (1.91:1) frame with object-fit:cover, so
  authors see the exact crop link previews will show; tip nudges 1200x630
- Article hero uses the same 1.91:1 ratio, so editor = hero = social all match
- Non-ideal covers are center-cropped for display only (file unchanged, no build
  cost) — authors see it and can swap
- Replace the broken info glyph with a native title tooltip on the whole label
…de frame

- New cropCover helper: center-crops to 1200x630 via canvas so only the previewed
  1.91:1 image is uploaded (og:image, hero, social all match) — no build cost
- Upload and pick-existing both route through addCroppedCover
- Remove button now sits outside the clipped frame via a holder wrapper
- build.format: 'file' → flat blog/x.html so URLs are /blog/x with no trailing
  slash (pairs with trailingSlash: 'never'); avoids Cloudflare's directory 308
- Preview-link bot posts the clean no-slash post URL
- Remove tsconfig baseUrl (removed in modern TS); paths already resolve relative
@HumbleBee14
HumbleBee14 merged commit e82725f into main Jul 14, 2026
2 checks passed
@HumbleBee14
HumbleBee14 deleted the feature/og-build-optimization branch July 14, 2026 13:33
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.

1 participant