Expand description
docgen-bases — a faithful, dependency-light engine and static HTML renderer
for Obsidian Bases.
A .base file is a YAML document describing filtered, sorted, grouped views
over a vault’s notes, computed from note frontmatter, file metadata, and an
expression language (functions, methods, operators, formulas, summaries). This
crate parses that YAML, evaluates the expression language over a caller-built
Corpus of Notes, and renders each view to self-contained HTML — no
scripts, no runtime — for build-time inclusion in a static site.
The crate is pure: it performs no I/O and knows nothing about docgen. The host
(docgen-build / docgen-core) constructs the Corpus from discovered docs and
supplies a RenderOptions with the site base path.
§Quick start
use docgen_bases::{render_base_source, Corpus, Note, RenderOptions};
let mut note = Note::default();
note.slug = "books/dune".into();
note.basename = "Dune".into();
note.tags = vec!["book".into()];
let corpus = Corpus::new(vec![note]);
let yaml = "filters:\n and:\n - file.hasTag(\"book\")\nviews:\n - type: table\n";
let html = render_base_source(yaml, &corpus, &RenderOptions::default());
assert!(html.contains("docgen-base-table"));Re-exports§
pub use model::parse_base;pub use model::BaseFile;pub use note::parse_date;pub use note::parse_wikilink;pub use note::properties_from_yaml;pub use note::value_from_yaml;pub use note::Corpus;pub use note::Note;pub use render::error_block;pub use render::render_base;pub use render::render_base_source;pub use render::RenderOptions;pub use value::BaseDate;pub use value::BaseLink;pub use value::Value;
Modules§
- ast
- Expression AST for the Bases language. A
Callwhosecalleeis aMemberis a method call (list.contains(x)); aCallon a bareIdentis a global function call (link("x")). The evaluator makes that distinction. - eval
- The tree-walking evaluator. Turns an
Exprinto aValueagainst anEvalCtx(the current note, the corpus, and the base’s formulas). It never panics: unknown identifiers, type mismatches, and out-of-range indices all resolve toValue::Null, matching Obsidian’s forgiving evaluation. - filter
- Compiles a
Filtertree into a set of parsed predicate expressions and evaluates it against a note. Global and view filters are AND-combined by the caller. A leaf expression that fails to parse is treated asfalse(the row is excluded) — surfaced separately as a diagnostic by the renderer. - format
- Date rendering: the default cell format plus a Moment.js format-string subset
for
date.format("YYYY-MM-DD"). Obsidian dates use Moment.js tokens; we implement the common subset and pass through any literal text (incl.[bracketed]literals). - functions
- The Bases function library: global functions (
link,date,if,list, …) and per-type methods (String/Number/Date/List/Link/File/Object/Any). All dispatch is name-based and total — an unknown name or a type mismatch yieldsValue::Null, never a panic. - lexer
- Tokenizer for the Bases expression language. Produces a flat token stream the
Pratt parser consumes. Tolerant: an unrecognized character becomes an
Errortoken the parser surfaces, rather than panicking. - model
- Serde model for a
.baseYAML file. Deserialization is deliberately tolerant: unknown keys are ignored, every section is optional, and the filter tree accepts either bare expression strings or nestedand/or/notmaps. - note
- The corpus: the set of notes a base queries over. Each
Notecarries its frontmatter properties (as typedValues) plus file metadata (file.*). The caller (docgen-build / docgen-core) constructs these from discovered docs; this crate stays free of any filesystem or docgen-specific types. - parser
- A Pratt (precedence-climbing) parser turning a token stream into an
Expr. Tolerant: on a syntax error it returnsErr(BaseError::Expr); callers render that as an inline error rather than failing the build. - render
- Static HTML rendering of a base’s views. Produces a self-contained
<div class="docgen-base">styled by the shareddocgen.css. Each view (table/cards/list) is filtered, sorted, grouped, and limited exactly as configured, then rendered to server-side HTML. - semver
- Version-aware column sorting.
- summary
- Column summary functions for a table’s footer row. Built-in summaries operate
over the set of a column’s cell values; a custom summary (defined in the
base’s
summaries:map) is an expression evaluated withvaluesbound to the column’s list of values. - value
- The typed value model shared by the evaluator, the function library, and the renderer. Mirrors Obsidian Bases’ runtime types: null, boolean, number, string, date, duration, list, object, and link.
Enums§
- Base
Error - Errors surfaced by the base engine. Parsing/eval degrade gracefully inside the renderer (producing error blocks / empty cells), so this is mostly for callers that want to parse a base explicitly.
Functions§
- view_
interactive_ enabled - Whether the interactive island should be enabled for
viewwithinbase.