Open Graph Images
Learn how to create custom Open Graph images for your documentation pages.
Basic usage
Section titled “Basic usage”To enable Open Graph images for your documentation pages, use the @stainless-docs/docs-og-image plugin. This plugin automatically generates Open Graph images using your pages title and description metadata.
- Install the plugin
Terminal window pnpm i @stainless-docs/docs-og-image - Add the plugin to your `astro.config.ts` file
astro.config.ts ...import stainlessDocsOgImage from '@stainless-api/docs-og-image';...export default defineConfig({...integrations: [stainlessDocs({...plugins: [stainlessDocsOgImage(),],}),],...}); - Set `site` within your astro config
For the Open Graph images to have correct URLs, you need to set the
siteproperty in yourastro.config.tsfile:astro.config.ts ...import stainlessDocsOgImage from '@stainless-api/docs-og-image';...export default defineConfig({...site: 'https://www.your-domain.com/',...});
Customize the Open Graph image
Section titled “Customize the Open Graph image”Use a custom logo
Section titled “Use a custom logo”By default, the plugin will use the logo defined in your stainless.config.ts file. If you are using a separate dark and light mode logo, the plugin will default to the light mode logo.
To use a custom logo for all Open Graph images, pass the logo option to the plugin:
export default defineConfig({ integrations: [ stainlessDocs({ ... plugins: [ stainlessDocsOgImage({ logo: './src/assets/og-logo.png', }), ], }), ], ...});Add a background image
Section titled “Add a background image”By default, the plugin will not use a background image. To add a custom background image to all Open Graph images, pass the backgroundImage option to the plugin:
export default defineConfig({ integrations: [ stainlessDocs({ ... plugins: [ stainlessDocsOgImage({ backgroundImage: { src: './src/assets/og-background.png', style?: { opacity: 0.3, height: '100%', width: '100%', left: 0, top: 0, } } }), ], }), ], ...});Change the theme
Section titled “Change the theme”By default, the plugin will generate Open Graph images using a light theme. To generate Open Graph images with a dark theme, pass the theme option to the plugin:
export default defineConfig({ integrations: [ stainlessDocs({ ... plugins: [ stainlessDocsOgImage({ theme: 'dark', }), ], }), ], ...});