"##,
title = escape(title),
css = stylesheet(),
nav = nav,
main = main
)
}
pub fn nav_html(files: &[PathBuf], active: Option<&str>, links: &LinkMode) -> String {
let mut out = String::from("
Files
");
let mut last_folder = String::new();
for f in files {
let rel = f.to_string_lossy().replace('\\', "/");
let folder = Path::new(&rel)
.parent()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_default();
if folder != last_folder {
if !folder.is_empty() {
out.push_str(&format!(
"
{}
",
escape(&folder)
));
}
last_folder = folder;
}
let name = Path::new(&rel)
.file_name()
.and_then(|s| s.to_str())
.unwrap_or(&rel);
let active_cls = if active == Some(rel.as_str()) {
" active"
} else {
""
};
let href = href_file(links, &rel);
out.push_str(&format!(
"
");
// index link for static pages
if matches!(links, LinkMode::Static { from: Some(_) }) {
let home = href_index(links);
out.insert_str(
0,
&format!(
"
".into()
} else {
// Prefer callers to render the first file at `/` / index.html; this is a fallback.
let first = files[0].to_string_lossy().replace('\\', "/");
format!(
"