Skip to content

fix(docs): attach default og:image to Markdoc metadata so docs pages show preview cards - #242

Open
adamshatzkamer wants to merge 1 commit into
gofr-dev:mainfrom
adamshatzkamer:feat/docs-og-image
Open

adamshatzkamer wants to merge 1 commit into
gofr-dev:mainfrom
adamshatzkamer:feat/docs-og-image

Conversation

@adamshatzkamer

Copy link
Copy Markdown

Closes #237

What

Docs pages that define nextjs.metadata.title/description in their markdown frontmatter emit their own openGraph/twitter metadata object. Next's metadata merge then replaces the root layout's openGraph.images instead of inheriting it — so shared docs links lost the social preview card entirely. Live example: https://gofr.dev/docs/ emits og:title/og:description and twitter:card, but no og:image and no twitter:image — LinkedIn/X/Slack render it as a plain text link.

This change attaches the site default social card (/opengraph-image.png, 1200×630, with alt) to the openGraph/twitter objects the markdoc loader emits — unless a page author explicitly sets their own images. Pages without frontmatter continue to inherit the root layout unchanged.

Why it matters

  • Every docs URL now shows a proper preview card when shared on LinkedIn, X, or Slack (acceptance criteria in Add og:image preview cards to docs pages #237).
  • Image carries og:image:width 1200, og:image:height 630, and og:image:alt so validators/ingestors see correct dimensions.
  • Zero footprint: no new assets — reuses the existing opengraph-image.png/twitter-image.png, no changes to authored content.

Verification

Reproduced the site's markdoc-metadata pipeline in a minimal Next 13.4 app with the same loader and root layout metadata, then ran next build and inspected exported HTML:

  • /docs/ (has frontmatter) → now emits og:image 1200×630 + og:image:alt + twitter:image ✓
  • /docs/plain (no frontmatter) → still inherits root layout image ✓

Only next.config.mjs changed (+30 lines).

…show preview cards

Docs pages that define nextjs.metadata title/description emit their own
openGraph/twitter object; Next's metadata merge replaces the parent
layout's images, so shared docs links lost the social preview card
entirely (only twitter:card was emitted, no og:image).

Attach the site default og:image/twitter:image (with width, height and
alt) whenever a page emits per-page openGraph/twitter values but does
not explicitly set images. Pages without frontmatter still inherit the
root layout unchanged.

Verified with a next build: /docs/ now emits
og:image 1200x630 + alt + twitter:image; /docs/plain (no frontmatter)
still inherits the layout image.
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.

Add og:image preview cards to docs pages

1 participant