aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: a6f8e1f1a0e489dcbf9dc3fe32da1e9b5373e3de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::fs;

fn main() {

    let config = match fs::read_to_string("settings.toml") {
        Ok(n) => simple_static_site_generator::Config::import(&(n.as_str())),
        Err(n) => {print!("\"settings.toml\": {}: ", n); simple_static_site_generator::Config::new()},
    };

    println!("{}", config.get_str("source").unwrap());

    let mut path_vec = vec![];
    let mut ex_path_vec = vec![];

    let dirs = fs::read_dir("src").unwrap();
    for dir in dirs {

        let path = dir.as_ref().unwrap().path();
        if path != std::path::PathBuf::from("assets") {
            path_vec.push(path);
        } else {
            ex_path_vec.push(path);
        }
    }

    println!("INCLUDED");
    for x in &path_vec {
        println!("{:?}", x)
    }
    println!("EXCLUDED");
    for x in &ex_path_vec {
        println!("{:?}", x)
    }
    println!();


    // create build directory or panic
    simple_static_site_generator::create_dir("build").unwrap();
    
    for path in path_vec {
        let mut file_string = String::new();
        
        if path.is_dir() {
            // RECURSE HERE
            continue
        }

        for line in fs::read_to_string(&path).unwrap().lines() {
            if line.contains(":?") {
                let v: Vec<&str> = line.trim().split(":?").collect();
                let v = v.get(1).unwrap();

                println!("INSERTING {} into {:?}", v, path);
                
                file_string.push_str(fs::read_to_string(v).unwrap().as_ref());
            } else {
                file_string.push_str(line);
                file_string.push('\n')
            }
        }
        
        
        let dest = simple_static_site_generator::replace_path_head(&path, "build/");

        // NEEDS TO CREATE DIRECTORY STRUCTURE
        fs::write(dest, file_string).expect("Could not write file");

    }


    // NEEDS TO COPY NOT SCANNED DIRECTORIES
}