1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::{fs, path::PathBuf};

use crate::templates::css::write_css_to_file;

pub struct Init;

impl Init {
    pub fn run(&self, path: &str) -> crate::BlogResult<()> {
        let posts_path = PathBuf::from(path).join("posts");
        let static_path = PathBuf::from(path).join("static");
        fs::create_dir_all(posts_path)
            .map_err(|e| crate::BlogError::io(e, "Unable to create posts directory".to_string()))?;
        fs::create_dir_all(&static_path).map_err(|e| {
            crate::BlogError::io(e, "Unable to create static directory".to_string())
        })?;
        // Create css file
        write_css_to_file(static_path.join("styles.css"))?;
        println!("Created blog-rs directory at {path:?}");
        Ok(())
    }
}