From 3c4c0000bec3f79f6e29bf7d482f23ec61753fe0 Mon Sep 17 00:00:00 2001 From: Montana Low Date: Wed, 11 Oct 2023 19:43:27 -0700 Subject: [PATCH 1/3] hide README in paths --- pgml-dashboard/src/api/docs.rs | 13 +++++++++---- pgml-dashboard/src/templates/docs.rs | 2 ++ pgml-dashboard/src/utils/markdown.rs | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pgml-dashboard/src/api/docs.rs b/pgml-dashboard/src/api/docs.rs index 34cfbc0f4..5ffea80c7 100644 --- a/pgml-dashboard/src/api/docs.rs +++ b/pgml-dashboard/src/api/docs.rs @@ -52,7 +52,6 @@ async fn doc_handler(path: PathBuf, cluster: &Cluster) -> Result( folder: &'a Path, content: &'a str, ) -> Result { - let url = path.clone(); + let mut path = path.to_str().expect("path must convert to a string").to_string(); + let mut url = path.clone(); + if path.ends_with("/") { + path.push_str("README"); + url.push_str("./"); + } + info!("it's a path: {:?} {:?}", path, url); // Get the document content let path = Path::new(&content) .join(folder) - .join(&(path.to_str().unwrap().to_string() + ".md")); + .join(&(path.to_string() + ".md")); info!("path: {:?}", path); // Read to string @@ -207,7 +212,7 @@ async fn render<'a>( // Handle navigation for nav_link in nav_links.iter_mut() { - nav_link.should_open(&url.to_str().unwrap().to_string()); + nav_link.should_open(&url); } let user = if cluster.context.user.is_anonymous() { diff --git a/pgml-dashboard/src/templates/docs.rs b/pgml-dashboard/src/templates/docs.rs index 311b02ca1..824e53cbc 100644 --- a/pgml-dashboard/src/templates/docs.rs +++ b/pgml-dashboard/src/templates/docs.rs @@ -42,6 +42,8 @@ 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 { + info!("self: {:?} | {:?}", self.href, path); + self.open = self.href.contains(&path); let open = if self.children.is_empty() { self.open diff --git a/pgml-dashboard/src/utils/markdown.rs b/pgml-dashboard/src/utils/markdown.rs index 7547d6d87..617b8a3ab 100644 --- a/pgml-dashboard/src/utils/markdown.rs +++ b/pgml-dashboard/src/utils/markdown.rs @@ -572,8 +572,11 @@ pub fn get_sub_links(list: &markdown::mdast::List) -> Result> { for node in link.children.iter() { match node { markdown::mdast::Node::Text(text) => { - let url = + let mut url = Path::new(&link.url).with_extension(""); + if url.ends_with("README") { + url = url.parent().unwrap().join("./").into(); + } let url = Path::new("/docs/guides") .join(url) .into_os_string() From 205fd9fdcec57b56ce4a7edce033035ce029d8bd Mon Sep 17 00:00:00 2001 From: Montana Low Date: Wed, 11 Oct 2023 19:43:49 -0700 Subject: [PATCH 2/3] fmt --- pgml-dashboard/src/api/docs.rs | 5 ++++- pgml-dashboard/src/utils/markdown.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pgml-dashboard/src/api/docs.rs b/pgml-dashboard/src/api/docs.rs index 5ffea80c7..6c93c8258 100644 --- a/pgml-dashboard/src/api/docs.rs +++ b/pgml-dashboard/src/api/docs.rs @@ -136,7 +136,10 @@ async fn render<'a>( folder: &'a Path, content: &'a str, ) -> Result { - let mut path = path.to_str().expect("path must convert to a string").to_string(); + let mut path = path + .to_str() + .expect("path must convert to a string") + .to_string(); let mut url = path.clone(); if path.ends_with("/") { path.push_str("README"); diff --git a/pgml-dashboard/src/utils/markdown.rs b/pgml-dashboard/src/utils/markdown.rs index 617b8a3ab..c4c6222a3 100644 --- a/pgml-dashboard/src/utils/markdown.rs +++ b/pgml-dashboard/src/utils/markdown.rs @@ -575,7 +575,8 @@ pub fn get_sub_links(list: &markdown::mdast::List) -> Result> { let mut url = Path::new(&link.url).with_extension(""); if url.ends_with("README") { - url = url.parent().unwrap().join("./").into(); + url = + url.parent().unwrap().join("./").into(); } let url = Path::new("/docs/guides") .join(url) From 1edac12e723afc06772e71329f9c878a1612f880 Mon Sep 17 00:00:00 2001 From: Montana Low Date: Wed, 11 Oct 2023 19:44:49 -0700 Subject: [PATCH 3/3] remove debugs --- pgml-dashboard/src/api/docs.rs | 2 -- pgml-dashboard/src/templates/docs.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/pgml-dashboard/src/api/docs.rs b/pgml-dashboard/src/api/docs.rs index 6c93c8258..89b1f286b 100644 --- a/pgml-dashboard/src/api/docs.rs +++ b/pgml-dashboard/src/api/docs.rs @@ -145,14 +145,12 @@ async fn render<'a>( path.push_str("README"); url.push_str("./"); } - info!("it's a path: {:?} {:?}", path, url); // Get the document content let path = Path::new(&content) .join(folder) .join(&(path.to_string() + ".md")); - info!("path: {:?}", path); // Read to string let contents = match tokio::fs::read_to_string(&path).await { Ok(contents) => contents, diff --git a/pgml-dashboard/src/templates/docs.rs b/pgml-dashboard/src/templates/docs.rs index 824e53cbc..311b02ca1 100644 --- a/pgml-dashboard/src/templates/docs.rs +++ b/pgml-dashboard/src/templates/docs.rs @@ -42,8 +42,6 @@ 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 { - info!("self: {:?} | {:?}", self.href, path); - self.open = self.href.contains(&path); let open = if self.children.is_empty() { self.open pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy