use walkdir::WalkDir; use std::fs::{self, File}; use std::path::Path; use handlebars::Handlebars; use std::io::Write; use toml::{Table, Value}; fn main() { // make public folder let _ = fs::remove_dir_all("public"); fs::create_dir("public").expect("could not make the folder \"public\""); //copy all static for e in WalkDir::new("static").into_iter().filter_map(|e| e.ok()) { if e.metadata().unwrap().is_file() { let mut path = e.path(); path = path.strip_prefix("static/").unwrap(); // should never fail fs::copy(e.path(), Path::new("public").join(path)).expect(&format!("failed to copy static/{} to public/{}", path.display(), path.display())); } } // make template let mut reg = Handlebars::new(); reg.register_template_string("main", fs::read_to_string("template.html.hbs").expect("cant read template.html.hbs")).expect("cant make template"); //format all pages for e in WalkDir::new("pages").into_iter().filter_map(|e| e.ok()) { if e.metadata().unwrap().is_file() { let path = e.path(); let contents = fs::read_to_string(path).expect(&format!("Cant read file {}", path.display())); let mut config = format!("{}\ncontent = \"\"", contents.split("+++").nth(1).expect(&format!("{} does not have a +++ section", path.display()))).parse::