Expand description
Β§Static Data Gen
A fast, secure, and comprehensive static site structured data generator library written in Rust.
β’ 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 informationrobots.txt
- Crawler instructionsmanifest.json
- PWA manifest
-
SEO Files
sitemap.xml
- Standard sitemapnews-sitemap.xml
- Google News sitemaprss.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Β§
- Content
Processing Error Builder - Builder for constructing
Error::ContentProcessing
variants. - IoError
Builder - Builder for constructing
Error::Io
variants. - Server
- Re-exports the
Server
type fromhttp_handle
.
EnumsΒ§
- Error
- Represents all possible errors within the StaticDataGen library.
- Error
Severity - 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 repeatedstd::result::Result<T, Error>
notation in function signatures.