Crate staticdatagen

Source
Expand description

StaticDataGen logo

Β§Static Data Gen

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

β€’ Website β€’ Documentation β€’ Report Bug β€’ Request Feature β€’ Contributing 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.5"

Β§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.

Re-exportsΒ§

pub use compiler::service::compile;
pub use utilities::uuid::generate_unique_string;

ModulesΒ§

compiler
The compiler module contains routines that parse and transform input data into static site outputs. It also holds mechanisms to streamline content transformations and validations, ensuring robust operation even under heavy loads.
generators
The generators module contains generators for creating various forms of static assets. These may include text files, images, or custom formats tailored to your application’s needs. Each generator is designed with consistency and security in mind.
locales
The locales module contains functionalities for handling multiple languages, including translations and localised templates. It assists with localised content generation tasks, ensuring that your static site can be adapted for various audiences.
macros
Macro definitions for repetitive or boilerplate-heavy operations reside in the macros module. By abstracting these patterns into macros, your codebase can remain succinct and easier to maintain.
models
The models module defines core data structures and types used throughout the library. By centralising these models in one place, you ensure a consistent contract for data across your application.
modules
The modules module comprises discrete functionalities that augment the core features of this library. For instance, it might include HTML generation, RSS feeds, or other structured content creation tasks. This segmentation keeps the library modular and maintainable.
utilities
The utilities module provides additional helpers and convenience functions, from string manipulation to generating unique identifiers. Designed to reduce boilerplate code, these utilities help you write concise, clear, and error-resilient Rust.

MacrosΒ§

macro_check_directory
Checks if a directory exists and creates it if necessary.
macro_cleanup_directories
Cleans up (removes) multiple directories.
macro_create_directories
Creates multiple directories at once.
macro_execute_and_log
Macro for executing a shell command with logging
macro_get_args
macro_get_args Macro
macro_log_complete
Macro for logging the completion of an operation
macro_log_error
Macro for logging an error
macro_log_info
Custom logging macro for various log levels and formats.
macro_log_start
Macro for logging the start of an operation
macro_metadata_option
macro_metadata_option Macro
macro_render_layout
macro_render_layout Macro
macro_serve
macro_serve Macro

StructsΒ§

ContentProcessingErrorBuilder
Builder for constructing Error::ContentProcessing variants.
IoErrorBuilder
Builder for constructing Error::Io variants.
Server
Re-exports the Server type from http_handle.

EnumsΒ§

Error
Represents all possible errors within the StaticDataGen library.
ErrorSeverity
Represents the severity level of an error.

ConstantsΒ§

VERSION
Specifies the version of the staticdatagen library.

Type AliasesΒ§

Result
A crate-specific Result type that defaults to using the library’s own [Error] variant. This reduces verbosity by eliminating repeated std::result::Result<T, Error> notation in function signatures.