pub struct Builder { /* private fields */ }Expand description
Configures and runs a Markdown → HTML build.
All directories are explicit — there are no ambient globals. templates_dir and
output_dir must be set via Builder::templates and Builder::output before
Builder::build is called.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(input_dir: impl Into<PathBuf>) -> Self
pub fn new(input_dir: impl Into<PathBuf>) -> Self
Starts a builder rooted at input_dir, the directory of .md source files.
Sourcepub fn output(self, dir: impl Into<PathBuf>) -> Self
pub fn output(self, dir: impl Into<PathBuf>) -> Self
Sets the output directory that mirrors input_dir, one .html file per .md file.
Sourcepub fn default_template(self, name: impl Into<String>) -> Self
pub fn default_template(self, name: impl Into<String>) -> Self
Sets the template used for pages that have no template: frontmatter key.
Sourcepub fn link_base(self, base: impl Into<String>) -> Self
pub fn link_base(self, base: impl Into<String>) -> Self
Sets the base path used to rewrite [x](x.md)-style links to clean URLs.
Sourcepub fn data_json(self, name: impl Into<String>) -> Self
pub fn data_json(self, name: impl Into<String>) -> Self
Opts into writing a data.json index of every non-draft page to name
(relative to output_dir) on every Builder::build — for a search index,
table of contents, or “recent items” list to consume.
Each entry has id, title, date, updated, version, url, summary,
tags, and pinned — the frontmatter-sourced fields default to "" ([]
for tags, false for pinned) when absent. A page with draft: true in
its frontmatter is excluded from both this index and the HTML build output.
Off by default; explicit over implicit, like the rest of Builder’s optional
features. Regenerated by both build() and crate::Watcher::tick (whenever
a .md file was added, removed, or modified — a template-only change never
alters index content, so it’s skipped then).
Sourcepub fn processor(self, processor: impl MarkdownProcessor + 'static) -> Self
pub fn processor(self, processor: impl MarkdownProcessor + 'static) -> Self
Registers a MarkdownProcessor to run on every page’s markdown body before
title/template resolution. Processors run in registration order.
Sourcepub fn analyzer(self, analyzer: impl MarkdownAnalyzer + 'static) -> Self
pub fn analyzer(self, analyzer: impl MarkdownAnalyzer + 'static) -> Self
Registers a MarkdownAnalyzer to run on every page’s markdown body after
processing, extracting metadata for the template. Analyzer results are merged
into the Tera context under page.extensions.<name()>.
Sourcepub fn watch(&self) -> Result<Watcher<'_>, DocError>
pub fn watch(&self) -> Result<Watcher<'_>, DocError>
Starts a watch session: an initial full Builder::build, then incremental
rebuilds via crate::Watcher::tick whenever a .md or template file’s mtime
changes. See Builder::build for the same required-configuration panics.
Sourcepub fn build(&self) -> Result<(), DocError>
pub fn build(&self) -> Result<(), DocError>
Walks input_dir and (re-)renders each non-draft .md file whose output
isn’t already up to date, writing the result under output_dir. If
Builder::data_json is set, also (re-)writes the page index.
A page’s HTML is skipped when output_path already exists and is at least as
new as both the .md file and every template file (the render cache —
cache::is_up_to_date internally). This makes repeat build() calls
incremental for free: no in-memory state, no cache to invalidate — the
filesystem’s own mtimes decide.
§Panics
Panics if .templates() or .output() were not called first — this is a
programmer error (missing required configuration), not a runtime data failure.