specify what dirs to create

This commit is contained in:
Tyrel Souza 2023-10-14 14:41:51 -04:00
parent b1ef76e2de
commit bfeae64c84
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
2 changed files with 12 additions and 4 deletions

View File

@ -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() {

View File

@ -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");