diff --git a/src/main.rs b/src/main.rs index 92b8532..c447a8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::{ }; fn main() { - let mut src_path = String::from("./"); + let mut src_path = String::from("./src"); let mut dist_path = String::from("./dist"); for arg in std::env::args() { if let Some(s) = arg.strip_prefix("--path=") { @@ -55,12 +55,29 @@ fn convert_all(src_path: &Path, dist_path: &Path) { "css" => convert_css(file, src_path, dist_path), "js" => convert_js(file, src_path, dist_path), "json" => convert_json(file, src_path, dist_path), - _ => Ok(()), + _ => copy(file, src_path, dist_path), } .unwrap(); } } +fn copy( + file: &Path, + src_path: &Path, + dist_path: &Path, +) -> Result<(), std::io::Error> { + if file.is_dir() { + return Ok(()); + } + let file_contents = std::fs::read(file)?; + let dist_path = dist_path.join(file.strip_prefix(src_path).unwrap_or(file)); + if let Some(path) = dist_path.parent() { + let _ = std::fs::create_dir_all(path); + } + std::fs::File::create(dist_path)?.write(&file_contents)?; + Ok(()) +} + fn convert_md( file: &Path, src_path: &Path, diff --git a/src/test.md b/src/test.md deleted file mode 100644 index 2be7c65..0000000 --- a/src/test.md +++ /dev/null @@ -1 +0,0 @@ -# hello world