/// Read in all files transitively referenced by `root_base_name`. /// /// This is the only input phase of the program, after this is processing and output. pub fn crawl(vault_dir: &Path, root_base_name: &str) -> HashMap<String, Page> { let mut visited: HashMap<String, Page> = HashMap::new(); let mut to_visit: Vec<String> = vec![root_base_name.to_string()]; while let Some(base_name) = to_visit.pop() { if visited.contains_key(&base_name) { continue; } let full_path = vault_dir.join(format!("{}.md", base_name)); let file_content = fs::read_to_string(&full_path) .unwrap_or_else(|_| panic!("Attempted to read the file {}", full_path.display())); let (metadata, hyperstring) = parse_page(&file_content); for reference in hyperstring.references() { to_visit.push(reference); } visited.insert( base_name, Page { metadata, hyperstring: hyperstring.clone(), }, ); } visited }