Skip to main content

Crate frontmatter_gen

Crate frontmatter_gen 

Source
Expand description

Frontmatter Gen logo

Frontmatter Gen

A Rust library for generating and parsing frontmatter in YAML, TOML, and JSON formats.

Build Crates.io Docs.rs Coverage lib.rs


§Install

cargo add frontmatter-gen

Or add to Cargo.toml:

[dependencies]
frontmatter-gen = "0.0.6"

You need Rust 1.56.0 or later. Works on macOS, Linux, and Windows.


§Overview

Frontmatter Gen extracts and generates frontmatter blocks from content files. It supports YAML, TOML, and JSON delimiters out of the box.

  • Auto-detection of frontmatter format from delimiters
  • Extraction of frontmatter and body content in a single pass
  • Generation of frontmatter blocks from Rust structs via Serde
  • Validation of required fields and structure

§Features

Multi-formatParse and generate YAML, TOML, and JSON frontmatter
ExtractionExtract frontmatter from Markdown and other content files
ValidationValidate frontmatter structure and required fields
Fenced blocksSupport for fenced (---, +++, {) delimiters
Serde integrationSerialize/deserialize to Rust structs via Serde

§Usage

use frontmatter_gen::extract;

fn main() {
    let content = r#"---
title: "My Post"
date: "2024-01-15"
---
This is the body."#;

    let (frontmatter, body) = extract(content).unwrap();
    println!("Title: {:?}", frontmatter.get("title"));
    println!("Body: {}", body);
}

§Development

cargo build        # Build the project
cargo test         # Run all tests
cargo clippy       # Lint with Clippy
cargo fmt          # Format with rustfmt

See CONTRIBUTING.md for setup, signed commits, and PR guidelines.


THE ARCHITECT \u1d2b Sebastien Rousseau THE ENGINE \u1d5e EUXIS \u1d2b Enterprise Unified Execution Intelligence System


§License

Dual-licensed under Apache 2.0 or MIT, at your option.

Back to Top

# Frontmatter Gen

frontmatter-gen is a fast, secure, and memory-efficient library for working with frontmatter in multiple formats (YAML, TOML, and JSON).

§Overview

This library provides robust handling of frontmatter with the following key features:

  • Zero-copy parsing for optimal memory efficiency
  • Type-safe operations with comprehensive error handling
  • Multiple format support (YAML, TOML, JSON)
  • Secure processing with input validation and size limits
  • Async support with the ssg feature flag

§Security Features

  • Input validation to prevent malicious content
  • Size limits to prevent denial of service attacks
  • Safe string handling to prevent memory corruption
  • Secure path handling for file operations

§Quick Start

use frontmatter_gen::{extract, Format, Frontmatter, Result};

let content = r#"---
title: Test Post
date: 2025-09-09
---
Content here"#;

let result = extract(content);
assert!(result.is_ok());
let (frontmatter, content) = result.unwrap();
assert_eq!(
    frontmatter.get("title").and_then(|v| v.as_str()),
    Some("Test Post")
);
assert_eq!(content.trim(), "Content here");

§Feature Flags

  • default: Core frontmatter functionality
  • cli: Command-line interface support
  • ssg: Static Site Generator functionality (includes CLI)

§Error Handling

All operations return a Result type with detailed error information. Use frontmatter.get("key") to access fields and pattern-match on Error variants for granular error handling.

Re-exports§

pub use crate::config::Config;
pub use crate::error::Error;
pub use crate::extractor::detect_format;
pub use crate::extractor::extract_raw_frontmatter;
pub use crate::parser::parse;
pub use crate::parser::to_string;
pub use crate::types::Format;
pub use crate::types::Frontmatter;
pub use crate::types::Value;

Modules§

cli
Command Line Interface Module
config
Configuration Module
engine
Site Generation Engine
error
Error handling for the frontmatter-gen crate.
extractor
This module provides functionality for extracting frontmatter from content.
parser
Front Matter Parser and Serialiser Module
prelude
Prelude module for convenient imports.
ssg
Static Site Generator Module
types
This module defines the core types used throughout the frontmatter-gen crate. It includes the Format enum for representing different frontmatter formats, the Value enum for representing various data types that can be stored in frontmatter, and the Frontmatter struct which is the main container for frontmatter data.
utils
Utility Module

Structs§

ParseOptions
Configuration options for parsing operations.

Constants§

MAX_FRONTMATTER_SIZE
Maximum size allowed for frontmatter content (1MB)
MAX_NESTING_DEPTH
Maximum allowed nesting depth for structured data

Functions§

extract
Extracts and parses frontmatter from content with format auto-detection.
to_format
Converts frontmatter to a specific format.
validate_input
Validates input content against security constraints.

Type Aliases§

Result
A specialized Result type for frontmatter operations.