use std::{collections::HashMap, fs, path::Path}; pub(crate) struct Parts { parts: HashMap, } impl Parts { pub(crate) fn new() -> Self { let mut parts = HashMap::new(); let parts_path = Path::new("templates/parts"); for part in fs::read_dir(parts_path).expect("No templates/parts folder") { let part = part.unwrap(); let filename = part.file_name().into_string().unwrap().to_string(); let filename = filename.replace(".html", ""); let path = format!("{}", part.path().display()); let template = fs::read_to_string(path).unwrap(); parts.insert(filename, template); } Self { parts } } pub(crate) fn perform(&self, input: String) -> String { let mut input = input; for (key, value) in &self.parts { let replace = format!("{{{{{}}}}}", key); input = input.replace(&replace, value); } input } }