Skip to content

linopress-cli/markdown ​

The Markdown files target, for VitePress or any other static site generator.

Interfaces ​

ApplyFilesOptions ​

Properties ​

PropertyTypeDescription
filesreadonly OutputFile[]-
force?booleanReplace 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-
outstringThe output folder. Created if missing.
ownedreadonly string[]The record the plan was made from (OutputState.owned).
planFilePlanThe plan to carry out, from planFiles over readOutputState(out, files).

FileAction ​

Properties ​

PropertyTypeDescription
adopted?booleanupdate 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.
kindFileActionKind-
pathstring-

FilePlan ​

Properties ​

PropertyTypeDescription
actionsreadonly FileAction[]Creates and updates in output order, then deletes, then unchanged files.
countsReadonly<Record<FileActionKind, number>>-
ownedreadonly string[]The record after applying: every file the edition writes.

MarkdownEdition ​

Properties ​

PropertyTypeDescription
filesreadonly OutputFile[]Pages first (in layout order), then assets by path.
missingImagesReadonly<Record<string, readonly string[]>>page path → local images and files it references that don't exist.
unresolvedLinksReadonly<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 ​

PropertyType
dataUint8Array
kind"page" | "asset"
pathstring

OutputState ​

What's in the output folder now, as far as the plan needs to know.

Properties ​

PropertyTypeDescription
existingReadonlyMap<string, Uint8Array<ArrayBufferLike>>Current bytes of the files the plan looked at; missing files are absent.
ownedreadonly string[]Files listed in the record (written by an earlier run).

RenderMarkdownOptions ​

Properties ​

PropertyTypeDescription
header?(node) => stringPut 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 ​

ts
type FileActionKind = "create" | "update" | "delete" | "unchanged";

FileEvent ​

ts
type FileEvent = object;

Properties ​

PropertyType
kind"created" | "updated" | "deleted"
pathstring

Variables ​

markdownTransforms ​

ts
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 ​

ts
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() ​

ts
function adoptedPaths(p): string[];

Paths of files the plan would replace although Linopress didn't write them.

Parameters ​

ParameterType
pFilePlan

Returns ​

string[]


applyFiles() ​

ts
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 ​

ParameterType
optionsApplyFilesOptions

Returns ​

Promise<void>


formatFilePlan() ​

ts
function formatFilePlan(p, options?): string;

Human-readable file plan, one line per file, in the style of formatPlan.

Parameters ​

ParameterType
pFilePlan
options?{ verbose?: boolean; }
options.verbose?boolean

Returns ​

string


isEmptyFilePlan() ​

ts
function isEmptyFilePlan(p): boolean;

True when applying the plan would write or delete nothing.

Parameters ​

ParameterType
pFilePlan

Returns ​

boolean


outputPath() ​

ts
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 ​

ParameterType
outstring
pathstring

Returns ​

string


planFiles() ​

ts
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 ​

ParameterType
filesreadonly OutputFile[]
stateOutputState

Returns ​

FilePlan


readOutputState() ​

ts
function readOutputState(out, files): Promise<OutputState>;

Reads the record and the current bytes of every file files writes or the record lists.

Parameters ​

ParameterType
outstring
filesreadonly OutputFile[]

Returns ​

Promise<OutputState>


readRecord() ​

ts
function readRecord(out): Promise<string[]>;

Reads the record; an empty list when there is none yet.

Parameters ​

ParameterType
outstring

Returns ​

Promise<string[]>


renderMarkdownEdition() ​

ts
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 ​

ParameterType
nodesreadonly DocNode[]
assetsReadonlyMap<string, Asset>
options?RenderMarkdownOptions

Returns ​

MarkdownEdition

MIT licensed. Not made by or affiliated with Linear.