Documentation framework

Starlight OG Image Integration

Add automatic per-page Open Graph images to Starlight documentation with the starlight-myog plugin or a native route middleware recipe.

Prerequisites

  • Starlight 0.33 or newer, with an Astro version supported by that Starlight release; the plugin supports Starlight 0.33 through 0.42
  • A production site URL configured in astro.config.mjs and publicly accessible documentation
  • A MyOG account with the public domain added and available image credits from a paid plan or the 10-day card trial

How MyOG fits Starlight

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.

1

Choose a layout

MyOG detects page content and branding automatically. The layout only controls image composition.

2

Add the Starlight code

Install plugin (Starlight 0.33 to 0.42)

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 code

Page and global og:image settings override MyOG. Remove src/myogRouteData.ts from routeMiddleware if you used the manual option.

Manual recipe (astro.config.mjs)

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 code

Manual recipe (src/myogRouteData.ts)

Add 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 code

Starlight already supplies twitter:card. The handler adds only missing image tags; page image overrides stay in control.

3

Place it correctly

  1. Set Astro's site to your public HTTPS origin.
  2. For the plugin, run pnpm add starlight-myog and add starlightMyOG to Starlight's plugins array. For the manual option, keep your existing Starlight options and add routeMiddleware pointing to src/myogRouteData.ts.
  3. For the manual option, if routeMiddleware is already configured, add this file to the existing array. The handler waits for later middleware before reading the final head.
  4. For the manual option, create src/myogRouteData.ts with the account-specific code below. Keep the account hint from your MyOG account; it identifies the installation and is not an API secret.
  5. Remove a global fallback og:image if you want MyOG on pages without a page-specific image. Remove that fallback's old image dimensions and alt text too.
  6. Build the site and inspect the generated HTML before publishing.

Avoid duplicate og:image tags

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.

Dynamic pages

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.

Test the result

  • Run your Astro build. In the home page and a nested docs page, confirm one og:image and one twitter:image, with the expected page URL after decoding the MyOG url parameter once.
  • Check a base-path or localized page and the configured trailing-slash behavior. The MyOG target should match the canonical link.
  • Give one page a frontmatter og:image and twitter:image. Confirm both overrides survive the build and unrelated title, description and canonical tags remain intact.
  • Confirm the 404 page has no generated MyOG tags. With site unset, neither option adds tags and the plugin logs a warning. An empty account hint makes the manual middleware add nothing; the plugin fails the build with an invalid account.

Start with the MyOG Open Graph Checker, then refresh social platform caches if needed.

Known limitations

The plugin was tested on Node.js 24 with astro build and an astro dev page check; a default build on Node.js 22 produced identical image tags. Its peer range is @astrojs/starlight >=0.33.0 <0.43.0; Starlight 0.43 and later need a new plugin release. A middleware that also uses order pre, is listed before the plugin, and adds an og:image after calling next() is not detected.
To uninstall the plugin, remove its entry from plugins and run pnpm remove starlight-myog, then rebuild.
Both options cover pages rendered by Starlight. Separate Astro pages need their own head setup, described in the Astro guide.
An existing global og:image prevents automatic images until you remove it. A custom Head component must render starlightRoute.head for the middleware to take effect.
Private documentation cannot be fetched by MyOG or public social crawlers. Account signup and the free metadata checker do not activate paid image serving; keep the domain registered and image credits available.

Sources

Ready to get started?

Create a MyOG account, add your docs domain, then start the card trial to serve images.

Already have an account?

d6da63065f957eac3c92e241d07decc62fced9b5