From 9d6b6fb5e3f180ec1a5b5859982eba69a7013c11 Mon Sep 17 00:00:00 2001 From: Montana Low Date: Thu, 12 Oct 2023 10:55:54 -0700 Subject: [PATCH 1/3] only highlite the active link --- pgml-dashboard/src/api/docs.rs | 3 +-- pgml-dashboard/src/templates/docs.rs | 22 ++++++++----------- pgml-dashboard/src/utils/markdown.rs | 9 ++++---- pgml-dashboard/templates/components/link.html | 16 +++++++++----- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/pgml-dashboard/src/api/docs.rs b/pgml-dashboard/src/api/docs.rs index 89b1f286b..db8e7bd6a 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 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..090cbec45 100644 --- a/pgml-dashboard/templates/components/link.html +++ b/pgml-dashboard/templates/components/link.html @@ -1,12 +1,12 @@