Expand description
Frontmatter Gen
A Rust library for generating and parsing frontmatter in YAML, TOML, and JSON formats.
§Install
cargo add frontmatter-genOr 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-format | Parse and generate YAML, TOML, and JSON frontmatter |
| Extraction | Extract frontmatter from Markdown and other content files |
| Validation | Validate frontmatter structure and required fields |
| Fenced blocks | Support for fenced (---, +++, {) delimiters |
| Serde integration | Serialize/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 rustfmtSee 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.
# Frontmatter Genfrontmatter-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
ssgfeature 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 functionalitycli: Command-line interface supportssg: 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
Formatenum for representing different frontmatter formats, theValueenum for representing various data types that can be stored in frontmatter, and theFrontmatterstruct which is the main container for frontmatter data. - utils
- Utility Module
Structs§
- Parse
Options - 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.