diff --git a/src/archive.rs b/src/archive.rs index 16475e1..f2aa3f4 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -22,6 +22,7 @@ pub fn read_dir(dir: &PathBuf) -> Vec { /// Rewrite all URLs in `input` to the format `/s//` fn internalize_urls(input: &str) -> String { + // TODO : Ignore blacklisted urls let url_pattern = r"https?://([a-zA-Z0-9.-]+)(/[\w./-]*)"; let re = regex::Regex::new(url_pattern).unwrap(); @@ -149,13 +150,18 @@ impl Document { /// # Returns /// A new `Document` instance. pub fn new(domain: &str, path: &str, base_dir: PathBuf) -> Self { + let split = path + .split('/') + .filter(|x| !x.is_empty()) + .collect::>(); + Self { domain: domain.to_string(), - path: path - .split('/') - .filter(|x| !x.is_empty()) - .collect::>() - .join("/"), + path: if split.is_empty() { + "/".to_string() + } else { + split.join("/") + }, base_dir, } } @@ -186,7 +192,7 @@ impl Document { versions.first().cloned()? }; - file_path = file_path.join(latest_version); + file_path = file_path.join(format!("index_{}.html", latest_version)); let content = std::fs::read_to_string(file_path).ok()?; @@ -204,7 +210,7 @@ impl Document { pub fn doc_dir(&self) -> PathBuf { let mut file_path = self.base_dir.join(&self.domain); - for p in self.path.split('/') { + for p in self.path.split('/').filter(|x| !x.is_empty()) { file_path = file_path.join(p); }