linopress-cli/markdown
The Markdown files target, for VitePress or any other static site generator.
Interfaces
ApplyFilesOptions
Properties
| Property | Type | Description |
|---|---|---|
files | readonly OutputFile[] | - |
force? | boolean | Replace files Linopress didn't write (adopted updates) and take them over. Without it, applyFiles throws before writing anything when the plan has any. |
onEvent? | (event) => void | - |
out | string | The output folder. Created if missing. |
owned | readonly string[] | The record the plan was made from (OutputState.owned). |
plan | FilePlan | The plan to carry out, from planFiles over readOutputState(out, files). |
FileAction
Properties
| Property | Type | Description |
|---|---|---|
adopted? | boolean | update only: the file exists but Linopress didn't write it (it isn't in the record), so a hand-written file would be replaced. applyFiles refuses this unless force is set. |
kind | FileActionKind | - |
path | string | - |
FilePlan
Properties
| Property | Type | Description |
|---|---|---|
actions | readonly FileAction[] | Creates and updates in output order, then deletes, then unchanged files. |
counts | Readonly<Record<FileActionKind, number>> | - |
owned | readonly string[] | The record after applying: every file the edition writes. |
MarkdownEdition
Properties
| Property | Type | Description |
|---|---|---|
files | readonly OutputFile[] | Pages first (in layout order), then assets by path. |
missingImages | Readonly<Record<string, readonly string[]>> | page path → local images and files it references that don't exist. |
unresolvedLinks | Readonly<Record<string, readonly string[]>> | page path → edition-relative .md link targets that aren't pages of this edition. |
OutputFile
A file the edition writes: a page or an asset it embeds, at its edition-relative path.
Properties
| Property | Type |
|---|---|
data | Uint8Array |
kind | "page" | "asset" |
path | string |
OutputState
What's in the output folder now, as far as the plan needs to know.
Properties
RenderMarkdownOptions
Properties
| Property | Type | Description |
|---|---|---|
header? | (node) => string | Put at the top of every page, e.g. an HTML comment saying the file is generated. |
transforms? | readonly MarkdownTransform[] | Defaults to markdownTransforms (none). |
Type Aliases
FileActionKind
type FileActionKind = "create" | "update" | "delete" | "unchanged";FileEvent
type FileEvent = object;Properties
| Property | Type |
|---|---|
kind | "created" | "updated" | "deleted" |
path | string |
Variables
markdownTransforms
const markdownTransforms: readonly MarkdownTransform[] = [];Transforms for a Markdown docs site: none. TypeDoc's <a id> anchors and #fragment links work on a normal site, so they are kept.
RECORD_FILE
const RECORD_FILE: ".linopress.json" = ".linopress.json";The file in the output folder that lists what Linopress wrote there. Only those files are ever deleted; anything else in the folder (a VitePress config, hand-written guides) is left alone.
Functions
adoptedPaths()
function adoptedPaths(p): string[];Paths of files the plan would replace although Linopress didn't write them.
Parameters
| Parameter | Type |
|---|---|
p | FilePlan |
Returns
string[]
applyFiles()
function applyFiles(options): Promise<void>;Writes created and updated files, deletes files of removed pages (and directories that become empty), and updates the record. The record is widened before the first write, so a run that stops halfway still knows which files are its own.
Parameters
| Parameter | Type |
|---|---|
options | ApplyFilesOptions |
Returns
Promise<void>
formatFilePlan()
function formatFilePlan(p, options?): string;Human-readable file plan, one line per file, in the style of formatPlan.
Parameters
| Parameter | Type |
|---|---|
p | FilePlan |
options? | { verbose?: boolean; } |
options.verbose? | boolean |
Returns
string
isEmptyFilePlan()
function isEmptyFilePlan(p): boolean;True when applying the plan would write or delete nothing.
Parameters
| Parameter | Type |
|---|---|
p | FilePlan |
Returns
boolean
outputPath()
function outputPath(out, path): string;Absolute path of an edition-relative path inside out. Throws for paths that would land outside it (a tampered record must not make Linopress delete files elsewhere).
Parameters
| Parameter | Type |
|---|---|
out | string |
path | string |
Returns
string
planFiles()
function planFiles(files, state): FilePlan;Diffs the files an edition writes against the output folder. Pure.
- not on disk → create; different bytes on disk → update; same bytes → unchanged. Compared with the disk, not a stored hash, so a file edited by hand is put back.
- in the record, no longer written, still on disk → delete.
Parameters
| Parameter | Type |
|---|---|
files | readonly OutputFile[] |
state | OutputState |
Returns
readOutputState()
function readOutputState(out, files): Promise<OutputState>;Reads the record and the current bytes of every file files writes or the record lists.
Parameters
| Parameter | Type |
|---|---|
out | string |
files | readonly OutputFile[] |
Returns
Promise<OutputState>
readRecord()
function readRecord(out): Promise<string[]>;Reads the record; an empty list when there is none yet.
Parameters
| Parameter | Type |
|---|---|
out | string |
Returns
Promise<string[]>
renderMarkdownEdition()
function renderMarkdownEdition(
nodes,
assets,
options?
): MarkdownEdition;Renders an edition as files: each page gets its title back as an H1 (sources split it off for Linear), links stay relative with their #fragments, and every embedded image that exists is copied to the same relative path, so references keep working.
Parameters
| Parameter | Type |
|---|---|
nodes | readonly DocNode[] |
assets | ReadonlyMap<string, Asset> |
options? | RenderMarkdownOptions |