Skip to content

markdown-source.ts#

View Markdown

Source

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

15 symbols 11 functions 3 interfaces 1 modules 28 parameters 11 members 11 returns

Reference#

fnbuildMarkdownSourceIndex(input: { files: readonly string[]; srcDir: string; permalinks?: ResolvedPermalinksOptions | null; cascade?: ResolvedCascadeOptions | null; publishState?: ResolvedPublishStateOptions; }): Promise<Map<string, MarkdownSourceIndexEntry>>Builds a companion index from source files without transforming Markdown.

Builds a companion index from source files without transforming Markdown.

Signature

export async function buildMarkdownSourceIndex(input: {
  files: readonly string[];
  srcDir: string;
  permalinks?: ResolvedPermalinksOptions | null;
  cascade?: ResolvedCascadeOptions | null;
  publishState?: ResolvedPublishStateOptions;
}): Promise<Map<string, MarkdownSourceIndexEntry>>

View source

Parameters

Returns

Promise<Map<string, MarkdownSourceIndexEntry>>
fninjectMarkdownSourceAlternate(html: string, href: string): stringInserts <link rel="alternate" type="text/markdown"> before </head>.

Inserts <link rel="alternate" type="text/markdown"> before </head>.

Signature

export function injectMarkdownSourceAlternate(html: string, href: string): string

View source

Parameters

  • html string
  • href string

Returns

string
fnisMarkdownSourceRequest(pathname: string): booleanTrue when the request pathname is a .md companion URL.

True when the request pathname is a .md companion URL.

Signature

export function isMarkdownSourceRequest(pathname: string): boolean

View source

Parameters

  • pathname string

Returns

boolean
modulemarkdown-sourceOpt-in Markdown source companions written beside generated HTML. Copies already-read source bytes. Does not re-parse Ma…

Opt-in Markdown source companions written beside generated HTML.

Copies already-read source bytes. Does not re-parse Markdown to emit them.

View source

fnmarkdownSourceHref(urlPath: string, base: string): string | undefinedPublic companion href, including base. Always ends in .md.

Public companion href, including base. Always ends in .md.

Signature

export function markdownSourceHref(urlPath: string, base: string): string | undefined

View source

Parameters

  • urlPath string
  • base string

Returns

string | undefined
fnmarkdownSourceHrefForPage(input: { source: string; fileUrl: string; frontmatter: Record<string, unknown>; base: string; permalinks?: ResolvedPermalinksOptions | null; cascade?: ResolvedCascadeOptions | null; publishState?: ResolvedPublishStateOptions; }): string | undefinedCompanion href for one page after permalink / publish-state checks.

Companion href for one page after permalink / publish-state checks.

Signature

export function markdownSourceHrefForPage(input: {
  source: string;
  fileUrl: string;
  frontmatter: Record<string, unknown>;
  base: string;
  permalinks?: ResolvedPermalinksOptions | null;
  cascade?: ResolvedCascadeOptions | null;
  publishState?: ResolvedPublishStateOptions;
}): string | undefined

View source

Parameters

Returns

string | undefined
interfaceMarkdownSourceIndexEntryOne entry in the dev-server companion index.

One entry in the dev-server companion index.

Signature

export interface MarkdownSourceIndexEntry

View source

Members

Properties
NameTypeDescription
allowed boolean
source string
fnmarkdownSourceOutputPath(outDir: string, urlPath: string): string | undefinedFilesystem path for a companion, or undefined when it would escape outDir.

Filesystem path for a companion, or undefined when it would escape outDir.

Signature

export function markdownSourceOutputPath(outDir: string, urlPath: string): string | undefined

View source

Parameters

  • outDir string
  • urlPath string

Returns

string | undefined
interfaceMarkdownSourcePageInputOne page that may receive a source companion.

One page that may receive a source companion.

Signature

export interface MarkdownSourcePageInput

View source

Members

Properties
NameTypeDescription
frontmatter Record<string, unknown>
inputPath string
sourceoptional string
Already-read source bytes. Omitted pages are skipped.
urlPath string
fnparseSourceFrontmatter(source: string): Record<string, unknown>Frontmatter keys only — not a Markdown parse.

Frontmatter keys only — not a Markdown parse.

Signature

export function parseSourceFrontmatter(source: string): Record<string, unknown>

View source

Parameters

  • source string

Returns

Record<string, unknown>
fnresolveMarkdownSourceOptions(value: boolean | MarkdownSourceOptions | undefined): ResolvedMarkdownSourceOptionsResolves ssg.markdownSource with defaults. false / omitted stays off. true enab…

Resolves ssg.markdownSource with defaults.

false / omitted stays off. true enables companions and the alternate link. An object enables the feature and overrides only the fields set.

Signature

export function resolveMarkdownSourceOptions(value: boolean | MarkdownSourceOptions | undefined): ResolvedMarkdownSourceOptions

View source

Parameters

Returns

ResolvedMarkdownSourceOptions
fnresolveMarkdownSourceRequest(pathname: string, index: ReadonlyMap<string, MarkdownSourceIndexEntry>): MarkdownSourceIndexEntry | undefinedLooks up a companion after the site base has been stripped.

Looks up a companion after the site base has been stripped.

Signature

export function resolveMarkdownSourceRequest(pathname: string, index: ReadonlyMap<string, MarkdownSourceIndexEntry>): MarkdownSourceIndexEntry | undefined

View source

Parameters

Returns

MarkdownSourceIndexEntry | undefined
fnshouldPublishMarkdownSource(frontmatter: Record<string, unknown>, publishState?: ResolvedPublishStateOptions): booleanWhether this page may publish a companion. Draft and unlisted source is never e…

Whether this page may publish a companion.

Draft and unlisted source is never emitted. When publishState is on, scheduled / expired pages follow that filter and includeDrafts is ignored so preview HTML cannot leak source.

Signature

export function shouldPublishMarkdownSource(frontmatter: Record<string, unknown>, publishState?: ResolvedPublishStateOptions): boolean

View source

Parameters

Returns

boolean
fnwriteMarkdownSourceFiles(input: WriteMarkdownSourceFilesInput): Promise<{ files: string[]; errors: string[] }>Writes enabled companions from already-read source bytes.

Writes enabled companions from already-read source bytes.

Signature

export async function writeMarkdownSourceFiles(input: WriteMarkdownSourceFilesInput): Promise<{ files: string[]; errors: string[] }>

View source

Parameters

Returns

Promise<{ files: string[]; errors: string[] }>
interfaceWriteMarkdownSourceFilesInputInputs for writing companions next to generated HTML.

Inputs for writing companions next to generated HTML.

Signature

export interface WriteMarkdownSourceFilesInput

View source

Members

Properties
NameTypeDescription
base string
optionsoptional ResolvedMarkdownSourceOptions | null
outDir string
pages readonly MarkdownSourcePageInput[]
publishStateoptional ResolvedPublishStateOptions