From 5e28d9549b6e66882ed5b7b5aba7453c11f9f28f Mon Sep 17 00:00:00 2001 From: curly Date: Tue, 3 Jan 2023 15:24:26 -0700 Subject: hardcoded, but functional --- Cargo.lock | 14 +++++++------- Cargo.toml | 2 +- TODO | 5 ++++- src/lib.rs | 46 +++++++++++++++++++++++++++++++--------------- src/main.rs | 6 +++--- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8c46fd..c73bf2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,18 +3,18 @@ version = 3 [[package]] -name = "serde" -version = "1.0.152" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" - -[[package]] -name = "simple_static_site_generator" +name = "s3g" version = "0.1.0" dependencies = [ "toml", ] +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" + [[package]] name = "toml" version = "0.5.10" diff --git a/Cargo.toml b/Cargo.toml index 86009c7..3e778aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "simple_static_site_generator" +name = "s3g" version = "0.1.0" edition = "2021" diff --git a/TODO b/TODO index 1bb5016..8a8c996 100644 --- a/TODO +++ b/TODO @@ -1 +1,4 @@ -Implement check_path() \ No newline at end of file +Check contents of files being read +Rework Config struct +Use Config values in assigning the build_dir location +Use Config values for check_path() \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 78d068b..344987d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,27 +121,43 @@ pub fn run(config: Config) { fn check_path(path: &path::PathBuf, config: &Config) -> PathType { // GET EXCLUDE AND DNS LISTS + let excludes: Vec = vec![path::PathBuf::from("nav.html")]; + let dns: Vec = vec![path::PathBuf::from("assets/")]; + + // Convert path to str for comparisons + let path = path.to_str().unwrap(); // CHECK FOR EXCLUDES AND DO NOT SCANS // Excludes - // for ex_path in excludes { - // if &ex_path == &path { - // return PathType::Exclude; - // } - // } - - // // Do not scans (copy files) - // for dns_path in dns { - // if &dns_path == &path { + for ex_path in excludes { + let ex_path = ex_path.to_str().unwrap(); + if &path.contains(&ex_path) == &true { + return PathType::Exclude; + } + } - // return PathType::DoNotScan; - // } - // } + // Do not scans (copy files) + for dns_path in dns { + let dns_path = dns_path.to_str().unwrap(); + if &path.contains(&dns_path) == &true { + return PathType::DoNotScan; + } + } - PathType::Exclude + return PathType::Okay; } -fn copy_file(path: &path::PathBuf) {} +fn copy_file(path: &path::PathBuf, config: &Config) { + let build_path = replace_path_head(&path, "build/"); + match fs::copy(path, build_path) { + Ok(_) => (), + Err(n) => { + if n.kind() != ErrorKind::AlreadyExists { + panic!() + } + }, + } +} fn directory_scan(path: path::PathBuf, config: &Config) { println!("Scanning: {:?}", &path); @@ -173,7 +189,7 @@ fn file_scan(path: path::PathBuf, config: &Config) { // Check path match check_path(&path, config) { PathType::Okay => (), - PathType::DoNotScan => {copy_file(&path); return}, + PathType::DoNotScan => {copy_file(&path, &config); return}, PathType::Exclude => return, }; diff --git a/src/main.rs b/src/main.rs index 9f24daf..3b75b65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,10 @@ 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()}, + Ok(n) => s3g::Config::import(&(n.as_str())), + Err(n) => {print!("\"settings.toml\": {}: ", n); s3g::Config::new()}, }; // Run - simple_static_site_generator::run(config); + s3g::run(config); } \ No newline at end of file -- cgit v1.2.3