mod nv;
use nv as nav;
use crate::bro;
use crate::app_consts;
use crate::unit;
use crate::bro::BrownError as Error;
pub fn get_nav(dir_path:&String)->String{
let mut sub_dirs:Vec<String> = Vec::new();
let sub_dirs_res =
bro::get_dirs(dir_path);
match sub_dirs_res {
Ok(item)=>{
let paths = item.into_iter()
.map(|i|bro::direntry_to_path(&i).unwrap()).collect::<Vec<String>>();
for path in paths{
let components = std::path::Path::new(&path).components();
let last = components.last();
let ll = last.unwrap();
let lll = ll.as_os_str();
let llll = lll.to_str().map(|s| s.to_string()).unwrap();
sub_dirs.push(llll);
(&dir_path, &sub_dirs);
}
let site_dir_path = dir_path.replace(
app_consts::HULK_DATA_DIR,
app_consts::HULK_SITE_DIR,
);
return nav::nav(&site_dir_path,&sub_dirs)
},
Err(_e)=>{
return "<header id='header'><nav class='links' style='--items: 1;'><a href='/index.html'>Home</a></nav></header>"
.to_string();},
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn basic(){
let _ = unit::create_demo_data_dir();
let d = get_nav(&"data".to_string());
}
}