build
Generates rendered Markdown files for many entries at once. Designed for SSG workflows.
import { build } from '@b4moss/hyogen-md'
function build(options: BuildOptions): Promise<BuildResult>
Options
type BuildOptions = RenderOptions & {
input: string | string[] // file paths or globs
outDir: string // output directory
includeUnderscoreEntries?: boolean
context?: HyogenContext
serverContext?: HyogenContext
}
| Option | Default | Description |
|---|---|---|
input | — | One or more entry paths or globs (Vite-style, via picomatch / fast-glob) |
outDir | — | Directory for rendered .md files |
context | {} | Shared template context for all entries |
serverContext | — | Server-only context merged per entry |
includeUnderscoreEntries | false | Include _ partial files as build entries |
loader | createNodeLoader() | Custom loader |
root | auto | Project root (.doc_root marker) |
preserveFrontMatter | false | Keep YAML front matter in output |
preserveHgComments | false | Keep <!-- @hg --> comments in output |
Entry discovery
By default, build:
- Matches
inputglobs - Filters out
_partials (files or paths under_directories) unlessincludeUnderscoreEntriesistrue - Walks
include/component/extenddependencies from each entry
Explicitly listed paths in input override the _ partial filter.
Example
import { build } from '@b4moss/hyogen-md'
const { files, warnings } = await build({
input: 'content/**/*.md',
outDir: 'dist/content',
context: { siteName: 'My Docs' },
serverContext: { buildTime: Date.now() },
})
for (const file of files) {
console.log(file.path, file.markdown.length)
}
Return value
type BuildResult = {
files: { path: string; markdown: string }[]
warnings: HyogenWarning[]
}
Files are also written to outDir. The files array lets you consume output in-process without reading disk.
Related
- renderServer
- Loader
- Paths and security —
_partials and.doc_root