pub fn nav(dir_path:&String,sub_dirs:&Vec<String>)->String{
let mut nav = String::from("<header id='header'><nav class='links' style='--items: 1;'><a href='/index.html'>Home</a>");
for sd in sub_dirs{
let link =
format!("<a href='./{}/index.html'>{}</a>",sd,sd);
nav.push_str(&link);
}
nav.push_str(&"</nav></header>");
return nav
}
pub fn fake()->String{
let static_data = r#"
<header id='header'>
<nav class='links' style='--items: 1;'>
<a href='./aa/bb/cc/index.html'>cc</a>
<a href='./aa/bb/dd/index.html'>dd</a>
<a href='./aa/bb/ee/index.html'>ee</a>
<a href='./aa/bb/ff/index.html'>ff</a>
</nav>
</header>"#;
static_data.to_string()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn excellent_test_no_confusion(){
let dir_path = String::from("site/aa/bb");
let mut sub_dirs:Vec<String> = Vec::new();
sub_dirs.push("cc".to_string());
sub_dirs.push("dd".to_string());
sub_dirs.push("ee".to_string());
sub_dirs.push("ff".to_string());
let r = nav(&dir_path,&sub_dirs);
println!("{:?}",r);
let static_data = r#"<header id='header'><nav class='links' style='--items: 1;'><a href='/index.html'>Home</a><a href='./cc/index.html'>cc</a><a href='./dd/index.html'>dd</a><a href='./ee/index.html'>ee</a><a href='./ff/index.html'>ff</a></nav></header>"#;
assert_eq!(r.as_str(),static_data);
}
}