shtola

ssg in rust
git clone https://tilde.team/~marisa/repo/shtola.git
Log | Files | Refs | LICENSE

commit fa3993a989ed97827085072435d3ba1bc95bbc09
parent ce51314db9f95737980fa57761cdd653ddd62cd3
Author: marisa <mokou@posteo.de>
Date:   Thu,  7 Nov 2019 15:57:09 +0100

base implementation

Diffstat:
MCargo.lock | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MCargo.toml | 2+-
Ashtola/Cargo.toml | 17+++++++++++++++++
Ashtola/src/lib.rs | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 226 insertions(+), 1 deletion(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -1,6 +1,139 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "im" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "sized-chunks 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "same-file" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "shtola" +version = "0.1.0" +dependencies = [ + "im 13.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "ware 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sized-chunks" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "typenum" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "walkdir" +version = "2.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ware" +version = "0.1.0" + +[[package]] name = "ware" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +[metadata] +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum im 13.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8db49f8bc08d5cc4e2bb0f7d25a6d1db2c79bc6f7d7c86c96c657eb3d214125f" +"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum sized-chunks 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f01db57d7ee89c8e053245deb77040a6cc8508311f381c88749c33d4b9b78785" +"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e" +"checksum ware 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "55b9c9f12bd457015eddc65fb44597e72b2091fc7e3ca250bb2a229969a9d589" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["ware"] +members = ["ware", "shtola"] diff --git a/shtola/Cargo.toml b/shtola/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "shtola" +description = "Minimal static site generator" +version = "0.1.0" +authors = ["marisa <mokou@posteo.de>"] +edition = "2018" +repository = "https://github.com/fmoko/shtola/tree/master/shtola" +documentation = "https://docs.rs/shtola" +homepage = "https://github.com/fmoko/shtola/tree/master/shtola" +readme = "README.md" +license-file = "LICENSE" + +[dependencies] +log = "0.4.8" +walkdir = "2.2.9" +ware = "0.1.0" +im = "13.0.0" diff --git a/shtola/src/lib.rs b/shtola/src/lib.rs @@ -0,0 +1,75 @@ +use ware::Ware; +use im::HashMap; +use std::path::PathBuf; +use std::default::Default; + +pub struct Shtola { + ware: Ware<IR>, + ir: IR, +} + +impl Shtola { + pub fn new<T: Into<PathBuf>>(dir: T) -> Shtola { + let mut config: Config = Default::default(); + config.directory = dir.into(); + let ir = IR { files: HashMap::new(), config }; + Shtola { ware: Ware::new(), ir } + } + + pub fn ignores(&mut self, vec: &mut Vec<PathBuf>) { + self.ir.config.ignores.append(vec); + self.ir.config.ignores.dedup(); + } + + pub fn source<T: Into<PathBuf>>(&mut self, path: T) { + self.ir.config.source = path.into(); + } + + pub fn destination<T: Into<PathBuf>>(&mut self, path: T) { + self.ir.config.destination = path.into(); + } + + pub fn clean(&mut self, b: bool) { + self.ir.config.clean = b; + } + + pub fn frontmatter(&mut self, b: bool) { + self.ir.config.frontmatter = b; + } + + pub fn r#use(&mut self, func: Box<dyn Fn(IR) -> IR>) { + self.ware.wrap(func); + } + + pub fn build(&mut self) -> IR { + // if clean is set, remove dest dir + // read files + let result_ir = self.ware.run(self.ir.clone()); + // write files + // return ir + result_ir + } +} + +#[derive(Clone)] +pub struct IR { + files: HashMap<PathBuf, ShFile>, + config: Config, +} + +#[derive(Clone, Default)] +pub struct Config { + ignores: Vec<PathBuf>, + directory: PathBuf, + source: PathBuf, + destination: PathBuf, + clean: bool, + frontmatter: bool, +} + + +#[derive(Clone)] +pub struct ShFile { + frontmatter: HashMap<String, String>, + content: Vec<u8>, +}