diff --git a/src/main.rs b/src/main.rs index 8d79dde..6e1324d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,17 +42,17 @@ fn render(input: &str) -> String { skin.term_text(input).to_string() } -async fn process_file(file: DirEntry, output_dir: PathBuf) { +async fn process_file(file: DirEntry, output_dir: PathBuf) -> Result<(), std::io::Error> { let markdown: &str = &std::fs::read_to_string(file.path()).unwrap(); let html_stripped = &remove_html(markdown); let links_replaced = &replace_links(html_stripped); let rendered = render(links_replaced); - write_file(output_dir, file, &rendered); + write_file(output_dir, file, &rendered) } -fn write_file(output_dir: PathBuf, file: DirEntry, rendered: &str) { +fn write_file(output_dir: PathBuf, file: DirEntry, rendered: &str) -> Result<(), std::io::Error> { let basename = file .path() .parent() @@ -65,9 +65,15 @@ fn write_file(output_dir: PathBuf, file: DirEntry, rendered: &str) { .to_string(); let name = basename.replace("awesome", "").replace("-", ""); - let path = output_dir.clone().join(name); + let mut path = output_dir.clone().join(name.clone()); - fs::write(path, rendered).expect("Error writing file!"); + let mut i = 2; + while path.exists() { + path.set_file_name(name.clone() + &i.to_string()); + i = i + 1; + } + + fs::write(path, rendered) } #[tokio::main]