Skip to content

Only highlight the active nav link #1067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pgml-dashboard/src/api/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::<Vec<&str>>();
let ((image, description), contents) = if parts.len() > 1 {
Expand Down
22 changes: 9 additions & 13 deletions pgml-dashboard/src/templates/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct NavLink {
pub href: String,
pub children: Vec<NavLink>,
pub open: bool,
pub active: bool,
}

impl NavLink {
Expand All @@ -23,6 +24,7 @@ impl NavLink {
href: "#".to_owned(),
children: vec![],
open: false,
active: false,
}
}

Expand All @@ -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
}
}

Expand Down
9 changes: 5 additions & 4 deletions pgml-dashboard/src/utils/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,12 @@ pub fn get_sub_links(list: &markdown::mdast::List) -> Result<Vec<NavLink>> {
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)
Expand Down
3 changes: 2 additions & 1 deletion pgml-dashboard/templates/components/link.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="nav flex-column" role="tablist" aria-orientation="vertical">
<%
let color = if open {

let color = if active {
"purple"
} else {
""
Expand Down
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