16 releases

0.4.4 Mar 19, 2023
0.4.2 Nov 10, 2021
0.3.0-alpha4 Jul 23, 2021
0.1.1 Jan 17, 2021
0.1.0 Nov 12, 2019

#58 in #static-site-generator

Download history 54/week @ 2024-09-28

54 downloads per month
Used in 2 crates

AGPL-3.0-or-later

26KB
495 lines

shtola

Shtola is a library for generic file processing. It enables you to build your own applications that function as static site generators! Here's an example:

use shtola::{Plugin, RefIR, ShFile, Shtola};
use std::time::SystemTime;

fn plugin() -> Plugin {
	Box::new(|mut ir: RefIR| {
		// Let's create our file in the IR (intermediate representation) file hash map!
		let current_time = SystemTime::now();
		ir.files.insert(
			"current_time.txt".into(),
			ShFile {
				content: format!("{:?}", current_time).into(),
				..ShFile::default()
			},
		);
	})
}

fn main() {
	let mut s = Shtola::new();
	s.source("fixtures/empty");
	s.destination("fixtures/dest_systemtime");
	s.register(plugin());
	s.build().expect("Build failed!");
	// Now we have a "current_time.txt" file in our destination directory that
	// contains the current system time!
}

Installation

Add the latest version of Shtola to your Cargo.toml.

Documentation

See https://docs.rs/shtola


lib.rs:

With Shtola, you can build your own static site generators easily. All that Shtola itself does is read files and frontmatter, run them through a bunch of user-provided plugins, and write the result back to disk.

As a demonstration of Shtola's basic piping feature, see this example:

use shtola::Shtola;

let mut m = Shtola::new();
m.source("../fixtures/simple");
m.destination("../fixtures/dest/doctest_example");
m.clean(true);
m.build().unwrap();

A "plugin" is just a boxed function that takes a RefMut to an IR (intermediate representation) struct. The plugin may modify the IR freely:

use shtola::{Plugin, ShFile, RefIR};

fn plugin() -> Plugin {
  Box::new(|mut ir: RefIR| {
    ir.files.insert("myFile".into(), ShFile::empty());
  })
}

Dependencies

~5–16MB
~194K SLoC