From 2be33f020de35372ec219dbe8024cce0e02fcfbe Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 3 Feb 2022 21:53:14 +0100 Subject: don't show files starting with a dot --- src/main.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6f4eb70..9385e01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -231,6 +231,12 @@ fn write_nav(file: &mut File, in_path: &Path, raw_path: &Path) continue } + // don't add items starting with a dot to the dropdown, they're + // hidden! + if name.starts_with(".") { + continue + } + //////////////////////////////////////////////////////////////////// file.write_all(format!(r#"
  • {}/
  • "#, link, name).as_bytes())?; @@ -305,6 +311,10 @@ fn write_same_level(file: &mut File, in_path: &Path, raw_path: &Path) let link_str = link.as_path().to_str().unwrap(); let name = link.file_name().unwrap().to_str().unwrap(); + if name.starts_with(".") { + continue + } + file.write_all(format!(r#"
  • {}/
  • "#, link_str, name).as_bytes())?; println!("\t\t{} {}", link_str, name); @@ -384,6 +394,13 @@ fn write_readme_content(file: &mut File, in_path: &Path, raw_path: &Path) .strip_prefix(raw_path) .expect("could not strip raw_path prefix"); + // write the link and the entry name to the file + let link = Path::new(raw_path).join(path); + let name = path.file_name().unwrap().to_str().unwrap(); + + if name.starts_with(".") { + continue + } // count the amount of segments in the path and write spaces for // each @@ -396,11 +413,47 @@ fn write_readme_content(file: &mut File, in_path: &Path, raw_path: &Path) let link = Path::new(raw_path).join(path); file.write_all( format!("{}\n", - link.display(), - path.file_name().unwrap().to_str().unwrap() + link.display(), name, ).as_bytes() )?; } + + } else if line.starts_with(":::toc") { + + for line in readme.split('\n') { + if line.starts_with("###") { + let line = line.get(4..).unwrap(); + file.write_all( + format!( + r##" {} +"##, + sanitize(line.to_string()), + line + ).as_bytes() + )?; + } else if line.starts_with("##") { + let line = line.get(3..).unwrap(); + file.write_all( + format!( + r##" {} +"##, + sanitize(line.to_string()), + line + ).as_bytes() + )?; + } else if line.starts_with("#") { + let line = line.get(2..).unwrap(); + file.write_all( + format!( + r##"{} +"##, + sanitize(line.to_string()), + line + ).as_bytes() + )?; + } + } + } else { -- cgit 1.4.1