diff --git a/src/file_utils.rs b/src/file_utils.rs index eea6a33..5465a8c 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -24,13 +24,17 @@ pub fn write_file(html: String) { fs::write("./public/links/index.html", html).expect("Could not write to index.html"); } -pub fn create_dirs() { +pub fn create_dirs(dirs: &[&str]) { if !Path::new("./public").exists() { fs::create_dir("./public").expect("Could not create public directory"); } - if !Path::new("./public/links").exists() { - fs::create_dir("./public/links").expect("Could not create public directory"); + for dir in dirs { + let path = format!("./public/{}", dir); + if !Path::new(&path).exists() { + fs::create_dir(&path).expect("Could not create public directory"); + } } + } pub fn delete_public_dir() { diff --git a/src/main.rs b/src/main.rs index b0da1ef..3b98c03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,8 +4,12 @@ use crate::links::{load_links,render_links}; fn main() { + // absolutely destroy any /public data, so we have a clean slate to write to file_utils::delete_public_dir(); - file_utils::create_dirs(); + file_utils::create_dirs(&[ + "links", + "blog" + ]); // Generate and Write Links let links_input = load_links("data/links/links.yaml");