diff --git a/pgml-dashboard/src/api/docs.rs b/pgml-dashboard/src/api/docs.rs index 89b1f286b..38d7ee56c 100644 --- a/pgml-dashboard/src/api/docs.rs +++ b/pgml-dashboard/src/api/docs.rs @@ -140,10 +140,9 @@ async fn render<'a>( .to_str() .expect("path must convert to a string") .to_string(); - let mut url = path.clone(); + let url = path.clone(); if path.ends_with("/") { path.push_str("README"); - url.push_str("./"); } // Get the document content @@ -153,8 +152,14 @@ async fn render<'a>( // Read to string let contents = match tokio::fs::read_to_string(&path).await { - Ok(contents) => contents, - Err(_) => return Err(Status::NotFound), + Ok(contents) => { + info!("loading markdown file: '{:?}", path); + contents + } + Err(err) => { + warn!("Error parsing markdown file: '{:?}' {:?}", path, err); + return Err(Status::NotFound); + } }; let parts = contents.split("---").collect::>(); let ((image, description), contents) = if parts.len() > 1 { diff --git a/pgml-dashboard/src/templates/docs.rs b/pgml-dashboard/src/templates/docs.rs index 311b02ca1..3e675c301 100644 --- a/pgml-dashboard/src/templates/docs.rs +++ b/pgml-dashboard/src/templates/docs.rs @@ -12,6 +12,7 @@ pub struct NavLink { pub href: String, pub children: Vec, pub open: bool, + pub active: bool, } impl NavLink { @@ -23,6 +24,7 @@ impl NavLink { href: "#".to_owned(), children: vec![], open: false, + active: false, } } @@ -42,20 +44,14 @@ impl NavLink { /// Automatically expand the link and it's parents /// when one of the children is visible. pub fn should_open(&mut self, path: &str) -> bool { - self.open = self.href.contains(&path); - let open = if self.children.is_empty() { - self.open - } else { - for child in self.children.iter_mut() { - if child.should_open(path) { - self.open = true; - } + self.active = self.href.ends_with(&path); + self.open = self.active; + for child in self.children.iter_mut() { + if child.should_open(path) { + self.open = true; } - - self.open - }; - - open + } + self.open } } diff --git a/pgml-dashboard/src/utils/markdown.rs b/pgml-dashboard/src/utils/markdown.rs index c4c6222a3..138d85067 100644 --- a/pgml-dashboard/src/utils/markdown.rs +++ b/pgml-dashboard/src/utils/markdown.rs @@ -572,11 +572,12 @@ pub fn get_sub_links(list: &markdown::mdast::List) -> Result> { for node in link.children.iter() { match node { markdown::mdast::Node::Text(text) => { - let mut url = - Path::new(&link.url).with_extension(""); + let mut url = Path::new(&link.url) + .with_extension("") + .to_string_lossy() + .to_string(); if url.ends_with("README") { - url = - url.parent().unwrap().join("./").into(); + url = url.replace("README", ""); } let url = Path::new("/docs/guides") .join(url) diff --git a/pgml-dashboard/templates/components/link.html b/pgml-dashboard/templates/components/link.html index 7dbbc02ab..57400d7ff 100644 --- a/pgml-dashboard/templates/components/link.html +++ b/pgml-dashboard/templates/components/link.html @@ -1,6 +1,7 @@