about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <git@emile.space>2022-02-03 21:54:49 +0100
committerEmile <git@emile.space>2022-02-03 21:54:49 +0100
commite9dfb0d7682dfbf30b33dc780377ab618c52e750 (patch)
treee2ecb4bd72a568af0aeb9eb08db8f95dd8b91d59
parentef7c7c7f6eaa0fb7b14dbe344ab749a1c86896cd (diff)
show_files directive
-rw-r--r--src/main.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 56a3f7f..9085649 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -272,6 +272,7 @@ fn write_same_level(file: &mut File, in_path: &Path, raw_path: &Path)
     let mut files: Vec<PathBuf> = Vec::new();
 
     let mut vertical: bool = false;
+    let mut show_files: bool = false;
 
     for entry in fs::read_dir(search_path)? {
         let path = &entry?.path();
@@ -285,6 +286,9 @@ fn write_same_level(file: &mut File, in_path: &Path, raw_path: &Path)
             if path.file_name().unwrap() == "vertical" {
                 vertical = true;
             }
+            if path.file_name().unwrap() == "show_files" {
+                show_files = true;
+            }
             println!("\t\t\t{:?}", path);
         }
     }
@@ -323,6 +327,36 @@ fn write_same_level(file: &mut File, in_path: &Path, raw_path: &Path)
     file.write_all(format!(r#"
   </ul>"#).as_bytes())?;
 
+    if files.len() >= 1 && show_files == true {
+        file.write_all(format!(r#"<br>
+    <ul>"#).as_bytes())?;
+
+        for f in files {
+            let f = f.canonicalize()?;
+            let f = f.strip_prefix(&in_path)
+                .expect("could not strip in_path prefix");
+
+            let link = Path::new("/").join(f);
+            let link_str = link.as_path().to_str().unwrap();
+            let name = link.file_name().unwrap().to_str().unwrap();
+
+            if name == "README.md"
+                || name == "show_files"
+                || name.starts_with(".")
+                {
+                continue
+            };
+
+            file.write_all(format!(r#"
+        <li><a href="{}">{}</a></li>"#, link_str, name).as_bytes())?;
+            println!("\t\t{} {}", link_str, name);
+        }
+
+        file.write_all(format!(r#"
+    </ul>"#).as_bytes())?;
+    }
+
+
     Ok(())
 }