API Reference

This page documents the public API of the taxus_lib generator library and taxus-common shared library.

taxus-common Crate

search Module

The search module provides full-text search with TF-IDF ranking.

SearchDocument

#![allow(unused)]
fn main() {
pub struct SearchDocument {
    pub id: u32,
    pub title: String,
    pub path: String,
    pub summary: String,
    pub tags: Vec<String>,
    pub categories: Vec<String>,
}
}

Metadata record for each indexed page.

MethodDescription
new(id, title, path, summary, tags, categories) -> SelfCreate a new document

SearchIndex

#![allow(unused)]
fn main() {
pub struct SearchIndex {
    pub documents: Vec<SearchDocument>,
    pub index: HashMap<String, Vec<(u32, f32)>>,
}
}

The main search index structure. The index maps word stems to (document_id, tfidf_score) pairs.

MethodDescription
new() -> SelfCreate empty index
add_document(&mut self, doc: SearchDocument, content: &str)Add a document with its content for indexing
search(&self, query: &str) -> Vec<&SearchDocument>Search and return ranked results
finalize(&mut self)Apply IDF weighting (call after all documents added)
to_bytes(&self) -> Vec<u8>Serialize to binary (postcard format)
from_bytes(bytes: &[u8]) -> SelfDeserialize from binary

Helper Functions

#![allow(unused)]
fn main() {
pub fn tokenize(text: &str) -> Vec<String>
}

Split text into lowercase tokens. Filters words shorter than 3 characters.

#![allow(unused)]
fn main() {
pub fn stem(tokens: &[String]) -> Vec<String>
}

Apply English Porter stemmer to tokens.


taxus-generator Crate

Re-exports

The library re-exports commonly used types from lib.rs:

#![allow(unused)]
fn main() {
// Configuration
pub use config::{BuildConfig, SiteConfig, SiteMeta};

// Content
pub use content::{ContentSource, FilesystemContentSource, Frontmatter, Page, Section};

// Templates
pub use templates::{
    PageContext, SectionContext, SiteContext, TemplateContext,
    TemplateRenderer, TeraRenderer,
};

// Assets
pub use assets::{AssetProcessor, AssetReport, ScssProcessor, StaticCopier};

// Build
pub use build::{BuildReport, ProcessedPage, RenderedPage, SiteBuilder};

// Feed
pub use feed::{FeedConfig, FeedEntry, FeedGenerator};

// Init
pub use init::{InitOptions, InitReport, InitScaffolder};

// Routes
pub use routes::{RouteDiscovery, RouteInfo, RouteKind, RouteRegistry};

// Errors
pub use error::{
    AssetError, ContentError, FeedError, GeneratorError, InitError,
    Result, RouteError, TemplateError,
};
}

config Module

SiteConfig

#![allow(unused)]
fn main() {
pub struct SiteConfig {
    pub site: SiteMeta,
    pub build: BuildConfig,
    pub feed: FeedConfig,
    pub base_dir: PathBuf,
}
}
MethodDescription
from_file(path: P) -> Result<Self>Load from file
from_dir(dir: P) -> Result<Self>Load from directory (looks for site.toml)
new(name, base_url) -> SelfCreate programmatically
validate(&self) -> Result<()>Validate required fields

SiteMeta

#![allow(unused)]
fn main() {
pub struct SiteMeta {
    pub name: String,
    pub base_url: String,
    pub description: Option<String>,
    pub author: Option<String>,
}
}

BuildConfig

#![allow(unused)]
fn main() {
pub struct BuildConfig {
    pub content_dir: PathBuf,    // default: "content"
    pub output_dir: PathBuf,     // default: "dist"
    pub static_dir: PathBuf,     // default: "static"
    pub styles_dir: PathBuf,     // default: "styles"
    pub templates_dir: PathBuf,  // default: "templates"
}
}

FeedConfig

#![allow(unused)]
fn main() {
pub struct FeedConfig {
    pub rss_enabled: bool,       // default: true
    pub atom_enabled: bool,      // default: false
    pub limit: usize,            // default: 0 (all)
    pub full_content: bool,      // default: false
    pub title: Option<String>,
    pub rss_path: Option<String>,
    pub atom_path: Option<String>,
}
}

content Module

Frontmatter

#![allow(unused)]
fn main() {
pub struct Frontmatter {
    pub title: String,
    pub description: Option<String>,
    pub date: Option<NaiveDate>,
    pub updated: Option<NaiveDate>,
    pub template: Option<String>,
    pub draft: bool,
    pub summary: Option<String>,
    pub slug: Option<String>,
    pub aliases: Vec<String>,
    pub tags: Vec<String>,
    pub categories: Vec<String>,
    pub series: Option<String>,
    pub extra: Option<toml::Value>,
    pub sort_by: SortBy,           // default: Date
    pub paginate_by: usize,
    pub paginate_template: Option<String>,
    pub weight: i32,
}
}
MethodDescription
from_str(s: &str) -> Result<Self, toml::de::Error>Parse from TOML
template(&self) -> &strGet template (default: "page.html")

Page

#![allow(unused)]
fn main() {
pub struct Page {
    pub frontmatter: Frontmatter,
    pub path: String,
    pub source: PathBuf,
    pub raw_content: String,
    pub content: Option<String>,
}
}
MethodDescription
from_file(path: P) -> Result<Self>Load from Markdown file
from_str(content: &str, source: &str) -> Result<Self>Parse from string
is_draft(&self) -> boolCheck if draft
url_path(&self) -> StringGet URL path
aliases(&self) -> &Vec<String>Get redirect aliases

Section

#![allow(unused)]
fn main() {
pub struct Section {
    pub frontmatter: Frontmatter,
    pub path: String,
    pub source: PathBuf,
    pub content: Option<String>,
    pub pages: Vec<Page>,
}
}
MethodDescription
from_dir(dir: P) -> Result<Self>Load from directory
add_page(&mut self, page: Page)Add a page
sort_by_date(&mut self)Sort by date (newest first)

ContentSource Trait

#![allow(unused)]
fn main() {
pub trait ContentSource: Send + Sync {
    fn load(&self, path: &Path) -> Result<String>;
    fn exists(&self, path: &Path) -> bool;
    fn list(&self) -> Result<Vec<PathBuf>>;
}
}

FilesystemContentSource

#![allow(unused)]
fn main() {
pub struct FilesystemContentSource { /* ... */ }
}
MethodDescription
new(root: P) -> SelfCreate with root directory

routes Module

RouteKind

#![allow(unused)]
fn main() {
pub enum RouteKind {
    Page,
    Section,
}
}

RouteInfo

#![allow(unused)]
fn main() {
pub struct RouteInfo {
    pub path: String,
    pub content_file: PathBuf,
    pub output_file: PathBuf,
    pub kind: RouteKind,
}
}

RouteRegistry

#![allow(unused)]
fn main() {
pub struct RouteRegistry { /* ... */ }
}
MethodDescription
new() -> SelfCreate empty registry
register(&mut self, route: RouteInfo)Register a route
get(&self, path: &str) -> Option<&RouteInfo>Get by path
contains(&self, path: &str) -> boolCheck existence
len(&self) -> usizeCount routes
iter(&self) -> impl Iterator<Item = &RouteInfo>Iterate all
pages(&self) -> impl Iterator<Item = &RouteInfo>Iterate pages
sections(&self) -> impl Iterator<Item = &RouteInfo>Iterate sections

RouteDiscovery

#![allow(unused)]
fn main() {
pub struct RouteDiscovery { /* ... */ }
}
MethodDescription
new(content_dir: P) -> SelfCreate with content directory
discover(&self) -> Result<RouteRegistry>Discover all routes

templates Module

TemplateRenderer Trait

#![allow(unused)]
fn main() {
pub trait TemplateRenderer: Send + Sync {
    fn render(&self, template: &str, context: &TemplateContext) -> Result<String>;
    fn register_template(&mut self, name: &str, content: &str) -> Result<()>;
    fn has_template(&self, name: &str) -> bool;
    fn load_templates(&mut self, dir: &Path) -> Result<()>;
}
}

TeraRenderer

#![allow(unused)]
fn main() {
pub struct TeraRenderer { /* ... */ }
}
MethodDescription
new() -> Result<Self>Create empty renderer
from_dir(dir: P) -> Result<Self>Create and load from directory

TemplateContext

#![allow(unused)]
fn main() {
pub struct TemplateContext {
    pub page: Option<PageContext>,
    pub section: Option<SectionContext>,
    pub site: SiteContext,
    pub now: NowContext,
    pub extra: HashMap<String, serde_json::Value>,
}
}
MethodDescription
new(site: SiteContext) -> SelfCreate with site
with_page(self, page: PageContext) -> SelfAdd page
with_section(self, section: SectionContext) -> SelfAdd section
with_extra(self, extra: HashMap) -> SelfAdd extra

PageContext

#![allow(unused)]
fn main() {
pub struct PageContext {
    pub title: String,
    pub description: Option<String>,
    pub path: String,
    pub permalink: String,
    pub content: String,
    pub raw_content: String,
    pub date: Option<String>,
    pub draft: bool,
    pub summary: String,
    pub word_count: usize,
    pub reading_time: usize,
    pub tags: Vec<String>,
    pub categories: Vec<String>,
    pub series: Option<String>,
}
}

SectionContext

#![allow(unused)]
fn main() {
pub struct SectionContext {
    pub title: String,
    pub description: Option<String>,
    pub path: String,
    pub content: Option<String>,
    pub pages: Vec<PageContext>,
    pub pagination: Option<PaginationContext>,
}
}

PaginationContext

#![allow(unused)]
fn main() {
pub struct PaginationContext {
    pub current: usize,
    pub total: usize,
    pub per_page: usize,
    pub total_items: usize,
    pub prev: Option<String>,
    pub next: Option<String>,
    pub first: String,
    pub last: String,
}
}

SiteContext

#![allow(unused)]
fn main() {
pub struct SiteContext {
    pub name: String,
    pub base_url: String,
    pub description: Option<String>,
    pub author: Option<String>,
}
}

NowContext

#![allow(unused)]
fn main() {
pub struct NowContext {
    pub year: i32,
}
}

build Module

SiteBuilder

#![allow(unused)]
fn main() {
pub struct SiteBuilder {
    config: SiteConfig,
    dry_run: bool,
    verbose: bool,
    include_drafts: bool,
}
}
MethodDescription
from_dir(dir: &Path) -> Result<Self>Create from directory
new(config: SiteConfig) -> SelfCreate from config
dry_run(self, bool) -> SelfSet dry-run mode
verbose(self, bool) -> SelfSet verbose mode
include_drafts(self, bool) -> SelfInclude drafts
build(self) -> Result<BuildReport>Run build pipeline
clean(self) -> Result<()>Clean output directory

build::pipeline::search Module (islands feature only)

GeneratedSearch

#![allow(unused)]
fn main() {
pub struct GeneratedSearch {
    pub search_index: Vec<u8>,
}
}

Container for the serialized search index.

FunctionDescription
generate_search(pages: &[ProcessedPage]) -> Result<GeneratedSearch>Create search index from processed pages
write_search_index(generated: &GeneratedSearch, output_dir: &Path, dry_run: bool) -> Result<()>Write search_index.bin to output

build::pipeline::wasm Module (islands feature only)

The WASM client is compiled at Cargo build time by taxus-generator/build.rs and embedded into the binary. At site build time, the embedded files are written to the output directory.

WasmBuildOutput

#![allow(unused)]
fn main() {
pub struct WasmBuildOutput {
    pub js_path: PathBuf,
    pub wasm_path: PathBuf,
    pub wasm_size: u64,
}
}

Result of writing the embedded WASM client files.

FunctionDescription
build_wasm_client(output_dir: &Path) -> Result<WasmBuildOutput>Write embedded client.js and client_bg.wasm to dist/wasm/

BuildReport

#![allow(unused)]
fn main() {
pub struct BuildReport {
    pub output_dir: PathBuf,
    pub pages_rendered: usize,
    pub sections_rendered: usize,
    pub drafts_skipped: usize,
    pub sitemap_urls: usize,
    pub assets: AssetReport,
    pub duration: Duration,
}
}
MethodDescription
print_summary(&self)Print summary
has_warnings(&self) -> boolCheck for warnings

ProcessedPage

#![allow(unused)]
fn main() {
pub struct ProcessedPage {
    pub route: RouteInfo,
    pub page: Page,
}
}

RenderedPage

#![allow(unused)]
fn main() {
pub struct RenderedPage {
    pub route: RouteInfo,
    pub html: String,
}
}

assets Module

AssetProcessor Trait

#![allow(unused)]
fn main() {
pub trait AssetProcessor: Send + Sync {
    fn process(&self, src: &Path, dest: &Path) -> Result<AssetReport>;
    fn handles(&self, path: &Path) -> bool;
    fn name(&self) -> &'static str;
}
}

ScssProcessor

#![allow(unused)]
fn main() {
pub struct ScssProcessor {
    include_paths: Vec<PathBuf>,
    minify: bool,
}
}
MethodDescription
new() -> SelfCreate with defaults
with_include_paths(paths: Vec<PathBuf>) -> SelfSet include paths
with_minify(bool) -> SelfSet minify

StaticCopier

#![allow(unused)]
fn main() {
pub struct StaticCopier {
    exclude_patterns: Vec<String>,
}
}
MethodDescription
new() -> SelfCreate with defaults
with_exclusions(patterns: Vec<String>) -> SelfSet exclusions

AssetReport

#![allow(unused)]
fn main() {
pub struct AssetReport {
    pub files_processed: usize,
    pub files_skipped: usize,
    pub errors: Vec<String>,
}
}
MethodDescription
merge(&mut self, other: AssetReport)Merge reports

init Module

InitOptions

#![allow(unused)]
fn main() {
pub struct InitOptions {
    pub name: String,
    pub base_url: String,
    pub force: bool,
    pub islands: bool,
}
}
MethodDescription
new(name, base_url) -> SelfCreate options
with_force(bool) -> SelfSet force
with_islands(bool) -> SelfSet islands

InitScaffolder

#![allow(unused)]
fn main() {
pub struct InitScaffolder { /* ... */ }
}
MethodDescription
new(options: InitOptions) -> SelfCreate scaffolder
scaffold(&self, path: &Path) -> Result<InitReport>Scaffold site

InitReport

#![allow(unused)]
fn main() {
pub struct InitReport {
    pub path: PathBuf,
    pub directories_created: usize,
    pub files_created: usize,
    pub created_dirs: Vec<PathBuf>,
    pub created_files: Vec<PathBuf>,
}
}

serve Module

DevServer

#![allow(unused)]
fn main() {
pub struct DevServer { /* ... */ }
}
MethodDescription
new(config: DevServerConfig) -> SelfCreate server
run(&self) -> Result<()>Start server (async)

DevServerConfig

#![allow(unused)]
fn main() {
pub struct DevServerConfig {
    pub site_dir: PathBuf,
    pub port: u16,
    pub output_dir: PathBuf,
}
}
MethodDescription
default() -> SelfCreate with defaults
with_port(self, port: u16) -> SelfSet port
with_output_dir(self, dir: PathBuf) -> SelfSet output dir
with_site_dir(self, dir: PathBuf) -> SelfSet site dir

error Module

GeneratorError

#![allow(unused)]
fn main() {
pub enum GeneratorError {
    Config(Box<ConfigError>),
    Content(Box<ContentError>),
    Template(Box<TemplateError>),
    Asset(Box<AssetError>),
    Route(Box<RouteError>),
    Init(Box<InitError>),
    Serve(Box<ServeError>),
    Feed(Box<FeedError>),
    Io { path: PathBuf, source: std::io::Error },
    NoContent,
    BrokenInternalLink { file: String, target: String },
    PageRenderFailed { path: String, source: TemplateError },
}
}
TypeDescription
ConfigErrorConfiguration errors (not found, parse, missing field)
ContentErrorContent errors (not found, frontmatter, IO)
TemplateErrorTemplate errors (not found, render, syntax)
AssetErrorAsset errors (SCSS, copy)
RouteErrorRoute errors (not found, duplicate, invalid)
FeedErrorFeed generation errors
ImageErrorImage processing errors
InitErrorInitialization errors (cancelled)
ServeErrorServer errors (port in use, WebSocket)
WasmErrorWASM build errors (tool missing, build failed)

Result

#![allow(unused)]
fn main() {
pub type Result<T> = std::result::Result<T, GeneratorError>;
}

tracing Module

FunctionDescription
init()Initialize with RUST_LOG env var
init_with_level(level: &str)Initialize with specific level