index.ts#
18 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
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 → launch browser (with using) → 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
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: OgImagePageEntry, templateFn: OgImageTemplateFn, templateSource: string, 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: OgImagePageEntry, templateFn: OgImageTemplateFn, templateSource: string, options: ResolvedOgImageOptions, cacheDir: string, session: OgBrowserSession, publicDir?: string): Promise<OgImageResult>Parameters
-
entryOgImagePageEntry -
templateFnOgImageTemplateFn -
templateSourcestring -
optionsResolvedOgImageOptions -
cacheDirstring -
sessionOgBrowserSession -
publicDirstringoptional
Returns
Promise<OgImageResult>
fnresolveOgImageOptions(options: OgImageOptions | undefined): ResolvedOgImageOptionsResolves user-provided OG image options with defaults.
Resolves user-provided OG image options with defaults.
Signature
export function resolveOgImageOptions(options: OgImageOptions | undefined): ResolvedOgImageOptionsParameters
-
optionsOgImageOptions | undefined
Returns
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: OgImagePageEntry[], templateSource: string, options: ResolvedOgImageOptions, cacheDir: string): Promise<OgImageResult[] | null>Tries to serve all pages from cache. Returns results if ALL pages are cached, n…
Tries to serve all pages from cache. Returns results if ALL pages are cached, null otherwise.
Signature
async function tryServeAllFromCache(pages: OgImagePageEntry[], templateSource: string, options: ResolvedOgImageOptions, cacheDir: string): Promise<OgImageResult[] | null>Parameters
-
pagesOgImagePageEntry[] -
templateSourcestring -
optionsResolvedOgImageOptions -
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