#static-site #templating #content-generation #directory-structure #structured-data

staticdatagen

A Rust library for generating structured data files and metadata for static sites, including HTML, RSS feeds, sitemaps, and SEO-optimized meta tags

1 unstable release

0.0.1 Oct 27, 2024

#49 in #static-site

Download history 114/week @ 2024-10-24 66/week @ 2024-10-31 142/week @ 2024-11-07 29/week @ 2024-11-14 21/week @ 2024-11-21

265 downloads per month
Used in 2 crates

MIT/Apache

315KB
6.5K SLoC

StaticDataGen logo

StaticDataGen

A fast, secure, and comprehensive static site structured data generator library written in Rust.

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

WebsiteDocumentationReport BugRequest FeatureContributing Guidelines

Overview 🚀

staticdatagen is a robust Rust library that streamlines the generation of structured data and metadata for static sites. It provides a comprehensive suite of tools for creating HTML files, RSS feeds, sitemaps, and SEO-friendly metadata, with built-in security features and multi-language support.

Features ✨

Content Generation & Processing

  • Markdown to HTML Conversion

    • Clean, semantic HTML output
    • Syntax highlighting support
    • Custom template integration
    • Content minification
  • Metadata Generation

    • OpenGraph and Twitter Card meta tags
    • JSON-LD support for rich snippets
    • Automatic metadata extraction
    • SEO optimization

Site Structure & Navigation

  • Navigation System

    • Automatic menu generation
    • Hierarchical structure support
    • Accessibility-compliant markup
    • Customizable formatting
  • Multi-language Support

    • Built-in support for English, French, and German
    • Extensible translation system
    • Language-specific templates
    • i18n content management

Data Format Support

  • Sitemaps

    • Standard XML sitemaps
    • Google News sitemaps
    • Automatic URL generation
    • Change frequency tracking
  • Feed Generation

    • RSS 2.0 support
    • Atom feed generation
    • Custom feed templates
    • Auto-updating timestamps

Security & Validation

  • Security Features

    • Path traversal prevention
    • Input sanitization
    • URL validation
    • Security.txt generation (RFC 9116)
  • Data Validation

    • Metadata verification
    • URL structure checking
    • Language code validation
    • Content integrity checks

Developer Experience

  • Error Handling

    • Comprehensive error types
    • Detailed error messages
    • Context-aware failures
    • Recovery suggestions
  • Performance

    • Efficient file processing
    • HTML minification
    • Parallel processing where possible
    • Memory-efficient operations

Installation 📦

Add staticdatagen to your Cargo.toml:

[dependencies]
staticdatagen = "0.0.1"

Directory Structure 📁

Create the following directory structure for your project:

your-project/
├── content/         # Your Markdown content
├── templates/       # HTML templates
├── build/          # Temporary build directory
└── site/           # Final output directory

Usage 💻

Basic Example

use staticdatagen::compiler::service::compile;
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Define paths for your static site
    let build_dir = Path::new("examples/build");            // Temporary build directory
    let content_dir = Path::new("examples/content");        // Source content directory
    let site_dir = Path::new("examples/site");              // Output directory
    let template_dir = Path::new("examples/templates");     // HTML templates directory

    // Compile the static site
    compile(
        build_dir,
        content_dir,
        site_dir,
        template_dir,
    )?;

    Ok(())
}

Generated Files 📄

The library generates the following files:

  • HTML Files

    • Minified and optimized
    • Accessibility-compliant
    • SEO-friendly structure
  • Metadata Files

    • security.txt - Security policy (RFC 9116)
    • humans.txt - Site credits and information
    • robots.txt - Crawler instructions
    • manifest.json - PWA manifest
  • SEO Files

    • sitemap.xml - Standard sitemap
    • news-sitemap.xml - Google News sitemap
    • rss.xml - Content syndication feed

Error Handling 🛠️

The library uses the anyhow crate for error handling, providing detailed error messages and context. All public functions return Result types with comprehensive error information:

use anyhow::Result;

fn main() -> Result<()> {
    // Your code here
    Ok(())
}

Performance 🚀

  • File Processing: Efficient streaming for large files
  • Minification: Optimized HTML output
  • Caching: Template and content caching
  • Memory Usage: Minimal memory footprint

Documentation 📚

For full API documentation, please visit docs.rs/staticdatagen.

Examples 🎯

To explore more examples, clone the repository and run 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 staticdatagen library.

Dependencies

~41–75MB
~1.5M SLoC