Documentation framework
Add automatic per-page Open Graph images to Starlight documentation with native route middleware and MyOG.social.
Starlight builds the head for each documentation page. Its route middleware can add a MyOG image URL to that head before the HTML is rendered, without a plugin package or client-side script.
The recipe reads Starlight's final canonical link, including the base path, locale and trailing slash. MyOG generates the image when the image URL is requested; the Astro build only writes metadata.
The editable head API was added in Starlight 0.33. This recipe was build-tested with Starlight 0.33.0 on Astro 5.18.0 and Starlight 0.42.6 on Astro 7.2.10. Other releases need their own build check.
MyOG detects page content and branding automatically. The layout only controls image composition.
Merge site and routeMiddleware into your existing configuration.
Preview anonymously. Sign in to get complete install code for your account.
Sign in to get install codeAdd image tags after Starlight and other route middleware have built the head.
Preview anonymously. Sign in to get complete install code for your account.
Sign in to get install codeStarlight already supplies twitter:card. The handler adds only missing image tags; page image overrides stay in control.
Starlight merges configured head tags with page frontmatter before this handler runs. The handler leaves any existing og:image untouched, including page overrides and global fallback images. When it adds MyOG, it preserves an existing twitter:image and Starlight's twitter:card. Middleware additions are not deduplicated automatically, so keep only one copy of this handler and inspect tags added by other integrations.
The canonical link supplies each home, docs, nested and localized URL. The entire URL is encoded once as a query value, preserving encoded path segments and reserved characters. A custom canonical must point to a public page on a domain registered in MyOG.
Start with the MyOG Open Graph Checker, then refresh social platform caches if needed.
Create a MyOG account, add your docs domain, then start the card trial to serve images.
Already have an account?
234557e8ea386a5b040a564592ebfc437920d0fb