diff --git a/src/renderer/html_handlebars.rs b/src/renderer/html_handlebars.rs index cd67ebd3..b1a18fb9 100644 --- a/src/renderer/html_handlebars.rs +++ b/src/renderer/html_handlebars.rs @@ -42,7 +42,7 @@ impl Renderer for HtmlHandlebars { if item.path != PathBuf::new() { let path = config.src().join(&item.path); - println!("Open file: {:?}", path); + let mut f = try!(File::open(&path)); let mut content: String = String::new(); @@ -68,10 +68,16 @@ impl Renderer for HtmlHandlebars { // Create an index.html from the first element in SUMMARY.md if index { + print!( + "Creating index.html from {:?}", + config.dest().join(&item.path.with_extension("html")) + ); + try!(fs::copy( - config.dest().join(path_to_link(&item.path).expect("Failed at creation of index.html")), + config.dest().join(&item.path.with_extension("html")), config.dest().join("index.html") )); + println!(" ✓"); index = false; } } @@ -106,8 +112,6 @@ impl HtmlHandlebars { fn create_file(working_directory: &Path, path: &Path) -> Result> { - println!("create_file:\n\t{:?}\n\t{:?}", working_directory, path); - // Extract filename let mut file_name; if let Some(name) = path.file_stem() { @@ -134,8 +138,6 @@ fn create_file(working_directory: &Path, path: &Path) -> Result constructed_path.push(&dir); - println!("constructed path= {:?}\ndir= {:?}", constructed_path, dir.as_os_str()); - // Check if path exists match metadata(&constructed_path) { // Any way to combine the Err and first Ok branch ?? @@ -146,7 +148,6 @@ fn create_file(working_directory: &Path, path: &Path) -> Result if !f.is_dir() { try!(fs::create_dir(&constructed_path)) } else { - println!("Exists ??"); continue } }, @@ -154,9 +155,11 @@ fn create_file(working_directory: &Path, path: &Path) -> Result } + print!("Create file: {:?}", constructed_path.join(&file_name)); let file = try!(File::create( - constructed_path.join(file_name) + constructed_path.join(&file_name) )); + println!(" ✓"); Ok(file) } @@ -210,25 +213,6 @@ fn render_html(text: &str) -> String { s } -fn path_to_link(path: &Path) -> Option { - // Extract filename - let mut file_name; - if let Some(name) = path.file_stem() { - file_name = String::from(name.to_str().unwrap()); - } - else { return None } - - file_name.push_str(".html"); - - // Change file name to .html - let mut path = path.to_path_buf(); - path.set_file_name(file_name); - - // Clean paths with './' - - Some(path) -} - fn path_to_root(path: &Path) -> String { // Remove filename and add "../" for every directory @@ -281,13 +265,17 @@ impl HelperDef for RenderToc { if path.len() > 0 { try!(rc.writer.write("".as_bytes())); true