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>