Frontmatter Gen (frontmatter-gen)
A high-performance Rust library for parsing and serialising frontmatter in YAML, TOML, and JSON formats. Engineered for safety, efficiency, and ease of use.
• Website • Documentation • Report Bug • Request Feature • Contributing Guidelines
Overview 🚀
frontmatter-gen is a robust Rust library that provides comprehensive 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 with performance and safety at its core.
Key Features 🎯
- Zero-copy parsing: Optimised for memory efficiency
- Multi-format support: Parse and serialise YAML, TOML, and JSON
- Type-safe operations: Comprehensive error handling with
Resulttypes - Secure processing: Input validation and size limits
- Async support: Full asynchronous operations via the
ssgfeature flag - Command-line interface: Direct frontmatter manipulation tools
- Memory safety: Guaranteed memory safety through Rust's ownership system
- Comprehensive testing: Extensive test coverage and validation
- Rich documentation: Detailed guides and examples
Available Features 🛠️
This crate provides several feature flags to customise its functionality:
- default: Core frontmatter parsing functionality
- cli: Command-line interface tools for validation and extraction
- ssg: Static Site Generator functionality (includes CLI features)
Configure features in your Cargo.toml:
[]
# Enable CLI support for validation and extraction
= { = "0.0.5", = ["cli"] }
# Enable all features (validation, extraction and static site generation)
= { = "0.0.5", = ["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.5", = ["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
# Validate frontmatter
Static Site Generation 🌐
Build and serve your static site:
# Generate a static site
# Or using cargo
Local Development Server
# Change to the output directory
# Start a local server (using Python for demonstration)
Visit http://127.0.0.1:8000 in your browser to view the site.
Error Handling 🚨
The library provides comprehensive error handling with context:
use ;
Logging Support 📝
Enable detailed logging with the standard Rust logging facade:
use extract;
use ;
use SimpleLogger;
CLI Logging Configuration
Control logging levels via environment variables:
# Set log level for CLI operations
RUST_LOG=debug
# Configure specific component logging
RUST_LOG=frontmatter_gen=debug,cli=info
Documentation 📚
Comprehensive documentation is available at:
Contributing 🤝
We welcome contributions! Please see our Contributing Guidelines for:
- Code of Conduct
- Development Process
- Pull Request Guidelines
- Issue Reporting
Licence 📝
This project is dual-licensed under either:
- Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- MIT Licence (http://opensource.org/licenses/MIT)
at your option.
Acknowledgements 🙏
Special thanks to all contributors and the Rust community for their invaluable support and feedback.