Skip to main content

output

Output helpers for formatter lifecycle hooks.

Hooks post-process pages the renderer has already written, so they must go through the same destination the renderer used. Reaching for the filesystem directly works only as long as the default adapter is in play, and silently misses every page when the output is redirected elsewhere.

readOptionalOutput()​

function readOptionalOutput(
filePath,
outputAdapter,
): Promise<string | undefined>;

Defined in: output.ts:84

Reads a file the formatter maintains itself, where absence is expected.

Unlike readOutput this reports nothing when there is no content: a navigation or metadata file legitimately does not exist until the formatter creates it on the first page of a directory.

Parameters​

filePath​

string

Path of the file to read

outputAdapter​

Maybe<OutputAdapter>

Adapter carried by the hook event, if any

Returns​

Promise<string | undefined>

The file content, or undefined when there is none


readOutput()​

function readOutput(filePath, outputAdapter): Promise<string | undefined>;

Defined in: output.ts:52

Reads back a page the renderer has written, through its output destination.

The page was just written, so nothing coming back means the destination cannot be read - a write-only adapter, a stubbed readFile, or a store that is not read-your-writes consistent. Post-processing cannot run without it, which is reported rather than silently skipped.

Parameters​

filePath​

string

Path of the generated page

outputAdapter​

Maybe<OutputAdapter>

Adapter carried by the hook event, if any

Returns​

Promise<string | undefined>

The page content, or undefined if it cannot be read back

Throws​

An error the first time this adapter cannot read a page back, so the skipped post-processing surfaces once instead of once per page.


rewriteRenderedPage()​

function rewriteRenderedPage(event, rewrite): Promise<void>;

Defined in: output.ts:123

Rewrites the content of a page a formatter has just rendered.

The read-modify-write around an afterRenderTypeEntities hook is identical for every preset that post-processes its own output; only the rewriting differs. Presets supply that and nothing else.

Parameters​

event​

unknown

The hook event, carrying the page path and its destination

rewrite​

(content, filePath, outputDir, baseURL) => string

Returns the new content, or the content unchanged to skip

Returns​

Promise<void>


writeOutput()​

function writeOutput(filePath, content, outputAdapter, dirPath?): Promise<void>;

Defined in: output.ts:98

Writes a file through the output destination, creating its directory first.

Parameters​

filePath​

string

Path of the file to write

content​

string

File content

outputAdapter​

Maybe<OutputAdapter>

Adapter carried by the hook event, if any

dirPath?​

string

Returns​

Promise<void>