Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
montanalow merged 3 commits intomasterfrommontana/paths
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionspgml-dashboard/src/api/docs.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -140,10 +140,9 @@ async fn render<'a>(
.to_str()
.expect("path must convert to a string")
.to_string();
letmuturl = 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 deletionspgml-dashboard/src/templates/docs.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionspgml-dashboard/src/utils/markdown.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionpgml-dashboard/templates/components/link.html
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp