index.ts#
22 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
Reference#
fncomputeTemplateSource(options: ResolvedOgImageOptions, root: string): Promise<string>Computes a stable template source identifier for cache keys. For custom templat…
Computes a stable template source identifier for cache keys.
For custom templates, hashes the file content so cache invalidates when the template changes. For the default template, returns a fixed string.
Signature
async function computeTemplateSource(options: ResolvedOgImageOptions, root: string): Promise<string>Parameters
-
optionsResolvedOgImageOptions -
rootstring
Returns
Promise<string>
fncreateSvelteCompilerPlugin(): import("rolldown").PluginCreates a rolldown plugin that compiles Svelte SFCs using svelte/compiler.
Creates a rolldown plugin that compiles Svelte SFCs using svelte/compiler.
Signature
function createSvelteCompilerPlugin(): import("rolldown").PluginReturns
import("rolldown").Plugin
fncreateVueCompilerPlugin(): import("rolldown").PluginCreates a rolldown plugin that compiles Vue SFCs using @vue/compiler-sfc.
Creates a rolldown plugin that compiles Vue SFCs using @vue/compiler-sfc.
Signature
function createVueCompilerPlugin(): import("rolldown").PluginReturns
import("rolldown").Plugin
fndefaultConcurrency(): numberHow many pages to render at once when the caller does not say. Rendering was se…
How many pages to render at once when the caller does not say.
Rendering was serial by default, so a site paid one Chromium page render per page, end to end. Pages are cheap next to the browser itself, but they are not free — this stays well under the core count so a build machine keeps room for everything else.
Signature
function defaultConcurrency(): numberReturns
number
fngenerateOgImages(pages: OgImagePageEntry[], options: ResolvedOgImageOptions, root: string): Promise<OgImageResult[]>Generates OG images for a batch of pages. Manages the full lifecycle: resolve t…
Generates OG images for a batch of pages.
Manages the full lifecycle: resolve template → select renderer → render each page (with caching and concurrency).
All errors are non-fatal: failures are reported in results but never throw.
Signature
export async function generateOgImages(pages: OgImagePageEntry[], options: ResolvedOgImageOptions, root: string): Promise<OgImageResult[]>Parameters
-
pagesOgImagePageEntry[] -
optionsResolvedOgImageOptions -
rootstring
Returns
Promise<OgImageResult[]>
fngetVizejsPlugin(): Promise<import("rolldown").Plugin[]>Loads @vizejs/vite-plugin as a rolldown plugin for Vue SFC compilation.
Loads @vizejs/vite-plugin as a rolldown plugin for Vue SFC compilation.
Signature
async function getVizejsPlugin(): Promise<import("rolldown").Plugin[]>Returns
Promise<import("rolldown").Plugin[]>
fnisBareSpecifier(id: string): booleanWhether id is a bare specifier, and so resolvable at runtime rather than someth…
Whether id is a bare specifier, and so resolvable at runtime rather than something the template bundle has to inline.
Template bundles are written to <root>/.cache/og-images/ and imported from there, so Node resolves anything left external against the project's own node_modules. Relative and absolute imports still bundle, which is what a template actually needs — its own components travel with it.
Signature
export function isBareSpecifier(id: string): booleanParameters
-
idstring
Returns
boolean
interfaceKeyedPageEntry extends OgImagePageEntryA page entry with its cache key computed once.
A page entry with its cache key computed once.
Signature
interface KeyedPageEntry extends OgImagePageEntryMembers
Properties
| Name | Type | Description |
|---|---|---|
key |
string |
fnmapWithSessions<Item, Result>(items: readonly Item[], sessions: readonly OgBrowserSession[], render: (item: Item, session: OgBrowserSession) => Promise<Result>): Promise<Result[]>Runs render over items, one at a time per session, in input order. A shared cur…
Runs render over items, one at a time per session, in input order.
A shared cursor rather than fixed batches: a batch waits for its slowest member before the next one starts, so one heavy card idled every other worker until it finished. Results are written by index, so the order the caller gets back does not depend on which session finished first.
Signature
export async function mapWithSessions<Item, Result>(items: readonly Item[], sessions: readonly OgBrowserSession[], render: (item: Item, session: OgBrowserSession) => Promise<Result>): Promise<Result[]>Parameters
-
itemsreadonly Item[] -
sessionsreadonly OgBrowserSession[] -
render(item: Item, session: OgBrowserSession) => Promise<Result>
Returns
Promise<Result[]>
interfaceOgImagePageEntryA single page entry for batch OG image generation.
A single page entry for batch OG image generation.
Signature
export interface OgImagePageEntryMembers
Properties
| Name | Type | Description |
|---|---|---|
outputPath |
string |
Absolute path to write the output PNG |
props |
OgImageTemplateProps |
Props to pass to the template |
interfaceOgImageResultResult of OG image generation for a single page.
Result of OG image generation for a single page.
Signature
export interface OgImageResultMembers
Properties
| Name | Type | Description |
|---|---|---|
cached |
boolean |
|
erroroptional |
string |
|
outputPath |
string |
variableconst OX_CONTENT_PACKAGE = /^@ox-content\/vite-plugin(\/.*)?$/Matches this package and every subpath it exports. A template's natural runtime…
Matches this package and every subpath it exports.
A template's natural runtime is whatever renders it, and for the framework-less kinds that is this package: renderToString, raw, when and each live at its root, and the JSX runtime under ./jsx-runtime. Inlining them instead drags the entire plugin — chokidar, fsevents and all — into the template bundle, which is what made importing it fail outright.
Signature
const OX_CONTENT_PACKAGE = /^@ox-content\/vite-plugin(\/.*)?$/fnrenderSinglePage(entry: KeyedPageEntry, templateFn: OgImageTemplateFn, options: ResolvedOgImageOptions, cacheDir: string, session: OgBrowserSession, publicDir?: string): Promise<OgImageResult>Renders a single page to PNG, with cache support.
Renders a single page to PNG, with cache support.
Signature
async function renderSinglePage(entry: KeyedPageEntry, templateFn: OgImageTemplateFn, options: ResolvedOgImageOptions, cacheDir: string, session: OgBrowserSession, publicDir?: string): Promise<OgImageResult>Parameters
-
entryKeyedPageEntry -
templateFnOgImageTemplateFn -
optionsResolvedOgImageOptions -
cacheDirstring -
sessionOgBrowserSession -
publicDirstringoptional
Returns
Promise<OgImageResult>
fnrenderSingleSatoriPage(entry: KeyedPageEntry, templateFn: OgImageTemplateFn, options: ResolvedOgImageOptions, cacheDir: string, root: string): Promise<OgImageResult>Renders a single page to PNG using Satori, with cache support.
Renders a single page to PNG using Satori, with cache support.
Signature
async function renderSingleSatoriPage(entry: KeyedPageEntry, templateFn: OgImageTemplateFn, options: ResolvedOgImageOptions, cacheDir: string, root: string): Promise<OgImageResult>Parameters
-
entryKeyedPageEntry -
templateFnOgImageTemplateFn -
optionsResolvedOgImageOptions -
cacheDirstring -
rootstring
Returns
Promise<OgImageResult>
fnresolveReactTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Resolves a React (.tsx/.jsx) template via SSR. Bundles with rolldown (JSX trans…
Resolves a React (.tsx/.jsx) template via SSR.
Bundles with rolldown (JSX transform), then wraps with react-dom/server renderToReadableStream for async Server Component support.
Signature
async function resolveReactTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Parameters
-
templatePathstring -
rootstring
Returns
Promise<OgImageTemplateFn>
fnresolveSvelteTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Resolves a Svelte SFC template via SSR. Compiles the SFC with svelte/compiler (…
Resolves a Svelte SFC template via SSR.
Compiles the SFC with svelte/compiler (server mode + runes), bundles with rolldown, then wraps with svelte/server render().
Signature
async function resolveSvelteTemplate(templatePath: string, root: string): Promise<OgImageTemplateFn>Parameters
-
templatePathstring -
rootstring
Returns
Promise<OgImageTemplateFn>
fnresolveTemplate(options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Resolves the template function from options. Dispatches by file extension: - .v…
Resolves the template function from options.
Dispatches by file extension:
.vue→ Vue SFC (SSR via vue/server-renderer).svelte→ Svelte SFC (SSR via svelte/server).tsx/.jsx→ React Server Component (SSR via react-dom/server)- others → TypeScript template (direct function export)
Signature
async function resolveTemplate(options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Parameters
-
optionsResolvedOgImageOptions -
rootstring
Returns
Promise<OgImageTemplateFn>
fnresolveTsTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Resolves a plain TypeScript template (existing behavior).
Resolves a plain TypeScript template (existing behavior).
Signature
async function resolveTsTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Parameters
-
templatePathstring -
optionsResolvedOgImageOptions -
rootstring
Returns
Promise<OgImageTemplateFn>
fnresolveVueTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Resolves a Vue SFC template via SSR. Compiles the SFC with @vue/compiler-sfc (o…
Resolves a Vue SFC template via SSR.
Compiles the SFC with @vue/compiler-sfc (or @vizejs/vite-plugin), bundles with rolldown, then wraps with createSSRApp + renderToString.
Signature
async function resolveVueTemplate(templatePath: string, options: ResolvedOgImageOptions, root: string): Promise<OgImageTemplateFn>Parameters
-
templatePathstring -
optionsResolvedOgImageOptions -
rootstring
Returns
Promise<OgImageTemplateFn>
fntryServeAllFromCache(pages: KeyedPageEntry[], cacheDir: string): Promise<OgImageResult[] | null>Serves every page from cache when all of them are present. The probe is an exis…
Serves every page from cache when all of them are present.
The probe is an existence check per key, not a read: on a partial hit this used to read and write every cached page before discovering the miss, then throw that work away and let the render loop redo it. Returns null when any page is missing, which is the signal that a renderer has to start.
Signature
async function tryServeAllFromCache(pages: KeyedPageEntry[], cacheDir: string): Promise<OgImageResult[] | null>Parameters
-
pagesKeyedPageEntry[] -
cacheDirstring
Returns
Promise<OgImageResult[] | null>
fntsTemplateBundleOptions(templatePath: string)Rolldown input options for a .ts template bundle. A .ts template is the framewo…
Rolldown input options for a .ts template bundle.
A .ts template is the framework-less kind, so it has no single runtime to externalize the way the .vue, .svelte and .tsx paths do — anything from node_modules is better resolved at import time than inlined. Nothing on this path has a compiler plugin, so nothing here needed bundling to be loadable in the first place.
Signature
export function tsTemplateBundleOptions(templatePath: string)Parameters
-
templatePathstring
fnwithCacheKeys(pages: OgImagePageEntry[], templateSource: string, options: ResolvedOgImageOptions): KeyedPageEntry[]Attaches the cache key to each entry. The key is a SHA-256 over the template so…
Attaches the cache key to each entry.
The key is a SHA-256 over the template source and the page props. It used to be recomputed three times per page — once to probe, once to read, once to write — over props that can be a whole frontmatter object.
Signature
function withCacheKeys(pages: OgImagePageEntry[], templateSource: string, options: ResolvedOgImageOptions): KeyedPageEntry[]Parameters
-
pagesOgImagePageEntry[] -
templateSourcestring -
optionsResolvedOgImageOptions