/** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ /** * `documentToMarkdown` — the document-grain markdown assembler for the * agent-readable export surface (`.md` routes, `llms.txt`). See * docs/05-reading-and-delivery/04-markdown-export.md. * * A page is a composite (text, richtext, blocks, arrays, relations); this * walks the collection's schema and the locale-resolved field data in * lockstep and emits ONE markdown document: YAML frontmatter, an H1 from * `useAsTitle`, then fields as sections. One-way and lossy-tolerant by * contract — the output is read-only and never re-imported. * * Editor-agnostic: rich-text leaves are delegated to the registered * `RichTextToMarkdownFn` (the seam beside `embed` / `populate` in * `ServerConfig.fields.richText`), passed in explicitly via options so * this module stays pure and unit-testable without `initBylineCore()`. * Routing knowledge stays out of core the same way: relation and file * URLs resolve through caller-supplied callbacks. * * Rendering rules (the format contract — see the unit tests): * - `useAsTitle` field → frontmatter `title` + body `# H1` (not repeated * as a section). * - A field named `summary` → frontmatter `description` + an unlabelled * lead paragraph (the standfirst). * - `richText` fields and `blocks` fields render their content directly, * with no `## Label` heading — they ARE the document body. * - Scalar fields (text, textArea, datetime, select, checkbox, numbers) * → `**Label:** value` lines. * - `relation` → `**Label:** [title](url)` when populated + resolvable. * - `image` / `file` → `![alt](url)`. * - `group` → `## Label` + nested walk; `array` → `## Label` + items. * - Empty values are skipped entirely — no empty headings. */ import { type CollectionDefinition, type RichTextToMarkdownFn } from '../@types/index.js'; export interface MarkdownSourceDocument { /** The document's URL slug (`byline_document_paths` projection). */ path?: string; /** Locale-resolved, camelCase field data (the `ClientDocument.fields` shape). */ fields: Record; updatedAt?: Date | string; } export interface DocumentToMarkdownOptions { /** * The content locale this render represents (one `.md` variant per * content locale — same cache key dimension as the HTML page). */ locale?: string; /** Absolute canonical URL of the HTML page; emitted into frontmatter. */ canonicalUrl?: string; /** * Rich-text serializer (the `ServerConfig.fields.richText.toMarkdown` * seam). Without it, rich-text leaves are skipped. */ richTextToMarkdown?: RichTextToMarkdownFn; /** * Resolve a relation target to a public URL. Receives the target's * collection path and document slug; return `undefined` to render the * relation as plain text (no link). */ resolveUrl?: (collectionPath: string, documentPath: string) => string | undefined; /** * Resolve an upload field value (`StoredFileValue`) to a public URL. * Falls back to the value's own `storageUrl`; the image is skipped when * neither yields a URL. */ resolveFileUrl?: (value: Record) => string | undefined; /** Extra frontmatter entries, merged after the standard keys. */ frontmatter?: Record; } /** * Render one document to a markdown string (frontmatter + body). */ export declare function documentToMarkdown(doc: MarkdownSourceDocument, definition: CollectionDefinition, options?: DocumentToMarkdownOptions): string;