#metadata #toml #yaml #json #data-file #file-processing #file-format

metadata-gen

A powerful Rust library for extracting, validating, and processing metadata in YAML, TOML, and JSON formats from any content or data file

1 unstable release

0.0.1 Oct 5, 2024

#26 in #file-processing

Download history 153/week @ 2024-09-30 52/week @ 2024-10-07 28/week @ 2024-10-14

233 downloads per month

MIT/Apache

84KB
1.5K SLoC

Metadata Gen logo

Metadata Gen (metadata-gen)

A powerful Rust library for extracting, validating, and processing metadata in YAML, TOML, and JSON formats from any content or data file.

Made With Love Crates.io lib.rs Docs.rs Codecov Build Status GitHub

WebsiteDocumentationReport BugRequest FeatureContributing Guidelines

Overview

metadata-gen is a robust Rust library designed for extracting, validating, and processing metadata from various content and data file formats. It focuses on the following key areas:

  • Parsing and serialization of metadata in YAML, TOML, and JSON formats
  • Extraction of frontmatter metadata from content files
  • Generation and management of meta tags for web content
  • Efficient processing of both local files and string content
  • Flexible integration with static site generators and content management systems

Key features include:

  • A unified API for handling metadata across different formats
  • Robust error handling and reporting
  • Customizable parsing options to accommodate various metadata structures
  • Asynchronous file processing capabilities
  • Utility functions for HTML entity escaping and unescaping
  • Type-safe metadata value handling through a custom Value enum
  • Generation of SEO-friendly meta tags from extracted metadata

metadata-gen aims to provide a stable and powerful foundation for metadata management across all platforms supported by Rust.

Installation

Add this to your Cargo.toml:

[dependencies]
metadata-gen = "0.0.1"

Usage

Here are some examples of how to use the library:

Extracting Metadata

use metadata_gen::extract_and_prepare_metadata;

let content = r#"---
title: My Post
description: A sample post
keywords: rust, metadata, extraction
---
Content here"#;

let result = extract_and_prepare_metadata(content);
if let Ok((metadata, keywords, meta_tags)) = result {
    println!("Metadata: {:?}", metadata);
    println!("Keywords: {:?}", keywords);
    println!("Meta tags: {}", meta_tags);
}

HTML Escape/Unescape Example

use metadata_gen::utils::{escape_html, unescape_html};

let original = "Hello <World> & \"Friends\"";
let escaped = escape_html(original);
let unescaped = unescape_html(&escaped);

println!("Original: {}", original);
println!("Escaped: {}", escaped);
println!("Unescaped: {}", unescaped);

Asynchronous File Processing

use metadata_gen::utils::async_extract_metadata_from_file;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (metadata, keywords, meta_tags) = async_extract_metadata_from_file("./examples/example.md").await?;
    println!("Metadata: {:?}", metadata);
    println!("Keywords: {:?}", keywords);
    println!("Meta tags: {}", meta_tags);
    Ok(())
}

Documentation

For full API documentation, please visit docs.rs/metadata-gen.

Examples

To run the examples, clone the repository and use the following command:

cargo run --example example_name

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under either of

at your option.

Acknowledgements

Special thanks to all contributors who have helped build the metadata-gen library.

Dependencies

~14–25MB
~393K SLoC