Skip to content

index.ts#

View Markdown

Source

11 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

11 symbols 8 functions 3 interfaces 25 parameters 6 members 8 returns

Reference#

fncomputeTemplateSource(options: ResolvedOgImageOptions, root: string, templateFn: OgImageTemplateFn): 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, templateFn: OgImageTemplateFn): Promise<string>

View source

Parameters

Returns

Promise<string>
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(): number

View source

Returns

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[]>

View source

Parameters

Returns

Promise<OgImageResult[]>
interfaceKeyedPageEntry extends OgImagePageEntryA page entry with its cache key computed once.

A page entry with its cache key computed once.

Extends

Signature

interface KeyedPageEntry extends OgImagePageEntry

View source

Members

Properties
NameTypeDescription
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[]>

View source

Parameters

Returns

Promise<Result[]>
interfaceOgImagePageEntryA single page entry for batch OG image generation.

A single page entry for batch OG image generation.

Signature

export interface OgImagePageEntry

View source

Members

Properties
NameTypeDescription
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 OgImageResult

View source

Members

Properties
NameTypeDescription
cached boolean
erroroptional string
outputPath string
fnrenderSingleBrowserlessPage(entry: KeyedPageEntry, templateFn: OgImageTemplateFn, options: ResolvedOgImageOptions, cacheDir: string, render: (html: string) => Promise<Buffer>): 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 renderSingleBrowserlessPage(entry: KeyedPageEntry, templateFn: OgImageTemplateFn, options: ResolvedOgImageOptions, cacheDir: string, render: (html: string) => Promise<Buffer>): Promise<OgImageResult>

View source

Parameters

Returns

Promise<OgImageResult>
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>

View source

Parameters

Returns

Promise<OgImageResult>
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>

View source

Parameters

Returns

Promise<OgImageResult[] | null>
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[]

View source

Parameters

Returns

KeyedPageEntry[]