markdown-source.ts#
15 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
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>>Parameters
-
input{ files: readonly string[]; srcDir: string; permalinks?: ResolvedPermalinksOptions | null; cascade?: ResolvedCascadeOptions | null; publishState?: ResolvedPublishStateOptions } -
input.filesreadonly string[] -
input.srcDirstring -
input.permalinks?ResolvedPermalinksOptions | nulloptional
-
input.cascade?ResolvedCascadeOptions | nulloptional
-
input.publishState?ResolvedPublishStateOptionsoptional
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): stringParameters
-
htmlstring -
hrefstring
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): booleanParameters
-
pathnamestring
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.
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 | undefinedParameters
-
urlPathstring -
basestring
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 | undefinedParameters
-
input{ source: string; fileUrl: string; frontmatter: Record<string, unknown>; base: string; permalinks?: ResolvedPermalinksOptions | null; cascade?: ResolvedCascadeOptions | null; publishState?: ResolvedPublishStateOptions } -
input.sourcestring -
input.fileUrlstring -
input.frontmatterRecord<string, unknown> -
input.basestring -
input.permalinks?ResolvedPermalinksOptions | nulloptional
-
input.cascade?ResolvedCascadeOptions | nulloptional
-
input.publishState?ResolvedPublishStateOptionsoptional
Returns
string | undefined
interfaceMarkdownSourceIndexEntryOne entry in the dev-server companion index.
One entry in the dev-server companion index.
Signature
export interface MarkdownSourceIndexEntryMembers
Properties
| Name | Type | Description |
|---|---|---|
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 | undefinedParameters
-
outDirstring -
urlPathstring
Returns
string | undefined
interfaceMarkdownSourcePageInputOne page that may receive a source companion.
One page that may receive a source companion.
Signature
export interface MarkdownSourcePageInputMembers
Properties
| Name | Type | Description |
|---|---|---|
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>Parameters
-
sourcestring
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): ResolvedMarkdownSourceOptionsParameters
-
valueboolean | MarkdownSourceOptions | undefined
Returns
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 | undefinedParameters
-
pathnamestring -
indexReadonlyMap<string, MarkdownSourceIndexEntry>
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): booleanParameters
-
frontmatterRecord<string, unknown> -
publishStateResolvedPublishStateOptionsoptional
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[] }>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 WriteMarkdownSourceFilesInputMembers
Properties
| Name | Type | Description |
|---|---|---|
base |
string |
|
optionsoptional |
ResolvedMarkdownSourceOptions | null |
|
outDir |
string |
|
pages |
readonly MarkdownSourcePageInput[] |
|
publishStateoptional |
ResolvedPublishStateOptions |