about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <git@emile.space>2022-02-03 21:53:14 +0100
committerEmile <git@emile.space>2022-02-03 21:53:14 +0100
commit2be33f020de35372ec219dbe8024cce0e02fcfbe (patch)
treeb83e98e3c7b20bb956f3369614619aa3b2af8c1e
parent59f376bf435f1832e9cb73d0f7355cd440988f1f (diff)
don't show files starting with a dot
-rw-r--r--src/main.rs57
1 files 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#"
                 <li><a href="{}">{}/</a></li>"#, 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#"
     <li><a href="{}">{}/</a></li>"#, 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!("<a href=\"/{}\">{}</a>\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##"       <a href="#{}">{}</a>
+"##,
+                            sanitize(line.to_string()),
+                            line
+                        ).as_bytes()
+                    )?;
+                } else if line.starts_with("##") {
+                    let line = line.get(3..).unwrap();
+                    file.write_all(
+                        format!(
+                            r##"    <a href="#{}">{}</a>
+"##,
+                            sanitize(line.to_string()),
+                            line
+                        ).as_bytes()
+                    )?;
+                } else if line.starts_with("#") {
+                    let line = line.get(2..).unwrap();
+                    file.write_all(
+                        format!(
+                            r##"<a href="#{}">{}</a>
+"##,
+                            sanitize(line.to_string()),
+                            line
+                        ).as_bytes()
+                    )?;
+                }
+            }
+
             
         } else {