Documentation framework
Add automatic per-page Open Graph images to Starlight documentation with the starlight-myog plugin or a native route middleware recipe.
Install starlight-myog for Starlight 0.33 through 0.42. The plugin registers route middleware that adds a MyOG og:image and twitter:image to each page's head. Existing page, config and route middleware images still win, with one exception listed under limitations.
The manual option below adds the same route middleware yourself, with no plugin package or client-side script. Use one option. When switching to the plugin, remove src/myogRouteData.ts from routeMiddleware; if both stay, tags are not duplicated, but the manual image URL is used.
Both options read 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. The plugin and recipe were build-tested with Starlight 0.33.0 on Astro 5.18.0 and Starlight 0.42.6 on Astro 7.2.10. Releases in between were not each tested; other releases need their own build check.
MyOG detects page content and branding automatically. The layout only controls image composition.
Run pnpm add starlight-myog in your Starlight site, then add the plugin to your existing astro.config.mjs. Keep your other Starlight plugins in the same array.
Preview anonymously. Sign in to get complete install code for your account.
Sign in to get install codePage and global og:image settings override MyOG. Remove src/myogRouteData.ts from routeMiddleware if you used the manual option.
Use this option without the plugin. 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 route middleware runs. Both options leave any existing og:image untouched, including page overrides and global fallback images. When either adds MyOG, it preserves an existing twitter:image and Starlight's twitter:card. Keep only one copy of the manual handler. Other integrations' middleware can add their own tags, so inspect the built output.
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?
d6da63065f957eac3c92e241d07decc62fced9b5