diff --git a/src/main.rs b/src/main.rs index 66f4847..fea5add 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,40 +1,22 @@ use std::{ error::Error, ffi::OsStr, - fs::{read_dir, read_to_string, DirBuilder, File}, + fs::{read_dir, read_to_string, File}, io::Write, path::{Path, PathBuf}, }; const SRC_DIR: &str = "write"; const OUT_DIR: &str = "site"; -const CONTENT_MARKER: &str = "CONTENT HERE"; - -const TEMPLATE_FILE: &str = "template.html"; -const DEFAULT_TEMPLATE: &[u8] = include_bytes!("../template.html"); - type Result = core::result::Result<(), Box>; fn main() -> Result { - if !PathBuf::from(TEMPLATE_FILE).is_file() { - File::create(TEMPLATE_FILE)?.write_all(DEFAULT_TEMPLATE)?; - println!("created {TEMPLATE_FILE}"); - } - if !PathBuf::from(SRC_DIR).is_dir() { - DirBuilder::new().create(SRC_DIR)?; - println!("created {SRC_DIR}/"); - } - if !PathBuf::from(OUT_DIR).is_dir() { - DirBuilder::new().create(OUT_DIR)?; - println!("created {OUT_DIR}/"); - } - let src_dir = PathBuf::from(SRC_DIR); build_dir(&src_dir) } fn build_dir(dir: &Path) -> Result { - for entry in read_dir(dir)?.flatten() { + for entry in read_dir(dir).unwrap().flatten() { let ftype = entry.file_type()?; if ftype.is_dir() { build_dir(&entry.path())?; @@ -74,13 +56,14 @@ fn convert_file(path: &Path) -> Result { html += "\n"; state = S::None; continue; + } else { + if state == S::P { + html += "

\n"; + } + state = S::Code; + html += "
\n";
+				continue;
 			}
-			if state == S::P {
-				html += "

\n"; - } - state = S::Code; - html += "
\n";
-			continue;
 		}
 
 		if state == S::Code {
@@ -115,12 +98,12 @@ fn convert_file(path: &Path) -> Result {
 		}
 	}
 
-	let template = read_to_string(TEMPLATE_FILE)?;
-	let html = template.replacen(CONTENT_MARKER, &html, 1);
+	let template = read_to_string("template.html")?;
+	let html = template.replace("CONTENT HERE", &html);
 
-	let mut file = File::create(&out_path)?;
+	let mut file = File::create(out_path)?;
 	file.write_all(html.as_bytes())?;
-	println!("built {}", out_path.display());
+
 	Ok(())
 }
 
diff --git a/template.html b/template.html
deleted file mode 100644
index 67f63de..0000000
--- a/template.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-	
-	
-	TITLE HERE
-
-
-
-	CONTENT HERE
-
-
-
\ No newline at end of file