Frontmatter Gen (frontmatter-gen)
A high-performance Rust library for parsing and serialising frontmatter in YAML, TOML, and JSON formats. Built for safety, efficiency, and ease of use.
• Website • Documentation • Report Bug • Request Feature • Contributing Guidelines
Overview 🚀
frontmatter-gen is a comprehensive Rust library that provides robust handling of frontmatter in content files. It delivers a type-safe, efficient solution for extracting, parsing, and serialising frontmatter in multiple formats. Whether you're building a static site generator, content management system, or any application requiring structured metadata, frontmatter-gen offers the tools you need.
Key Features 🎯
- Zero-copy parsing for optimal memory efficiency
- Multi-format support (YAML, TOML, JSON)
- Type-safe operations with comprehensive error handling
- Secure processing with input validation and size limits
- Async support with the
ssgfeature flag - Command-line interface for direct manipulation
Available Features 🛠️
This crate provides several feature flags to customise its functionality:
- default: Core frontmatter parsing functionality only
- cli: Command-line interface tools for quick operations
- ssg: Static Site Generator functionality (includes CLI features)
Configure features in your Cargo.toml:
[]
# Enable CLI support for validation and extraction
= { = "0.0.4", = ["cli"] }
# Enable all features (validation, extraction and static site generation)
= { = "0.0.4", = ["ssg"] }
Installation via cargo:
# Install with CLI support
# Install with SSG support
Getting Started 📦
Library Usage
Add this to your Cargo.toml:
[]
# Core library with command-line interface and SSG support
= { = "0.0.4", = ["cli", "ssg"] }
Basic Usage 🔨
Extract and Parse Frontmatter
use extract;
Format Conversion
use ;
CLI Tool 🛠️
The fmg command provides comprehensive frontmatter operations:
# Extract frontmatter in various formats
# Save extracted frontmatter
# Validate frontmatter
You can also use the CLI directly from the source code:
# Extract frontmatter in various formats
# Save extracted frontmatter
Static Site Generation 🌐
Build and serve your static site:
# Generate a static site with the fmg CLI
# Generate a static site using cargo
Serve locally (using Python for demonstration)
# Change to the output directory
# Serve the site
Then visit http://127.0.0.1:8000 in your favourite browser.
Error Handling 🚨
The library provides comprehensive error handling:
use ;
Logging Support 📝
When the logging feature is enabled, the library integrates with Rust's log crate for detailed debug output. You can use any compatible logger implementation (e.g., env_logger, simple_logger).
Basic Logging Setup
use extract;
use ;
;
static LOGGER: SimpleLogger = SimpleLogger;
Advanced Logging Configuration
For more control over logging:
use ;
use ;
;
static LOGGER: SimpleLogger = SimpleLogger;
CLI Logging 📝
When using the CLI with logging enabled:
# Set log level via environment variable
RUST_LOG=debug
# Or for more specific control
RUST_LOG=frontmatter_gen=debug,cli=info
The library provides detailed error handling with context:
use ;
Documentation 📚
For comprehensive API documentation and examples, visit:
Contributing 🤝
We welcome contributions! Please see our Contributing Guidelines for details on:
- Code of Conduct
- Development Process
- Submitting Pull Requests
- Reporting Issues
Licence 📝
This project is dual-licensed under either:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT licence (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgements 🙏
Special thanks to all contributors and the Rust community for their invaluable support and feedback.