Repository navigation
fix(docs): attach default og:image to Markdoc metadata so docs pages show preview cards - #242
Open
adamshatzkamer wants to merge 1 commit into
Open
adamshatzkamer wants to merge 1 commit into
adamshatzkamer wants to merge 1 commit into
Conversation
…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.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #237
What
Docs pages that define
nextjs.metadata.title/descriptionin their markdown frontmatter emit their ownopenGraph/twittermetadata object. Next's metadata merge then replaces the root layout'sopenGraph.imagesinstead of inheriting it — so shared docs links lost the social preview card entirely. Live example:https://gofr.dev/docs/emitsog:title/og:descriptionandtwitter:card, but noog:imageand notwitter:image— LinkedIn/X/Slack render it as a plain text link.This change attaches the site default social card (
/opengraph-image.png, 1200×630, withalt) to theopenGraph/twitterobjects 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
og:image:width1200,og:image:height630, andog:image:altso validators/ingestors see correct dimensions.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 buildand inspected exported HTML:/docs/(has frontmatter) → now emitsog:image1200×630 +og:image:alt+twitter:image✓/docs/plain(no frontmatter) → still inherits root layout image ✓Only
next.config.mjschanged (+30 lines).