Skip to content

Commit d0c2643

Browse files
authored
hide README extension in urls (#1065)
1 parent 8788c2b commit d0c2643

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pgml-dashboard/src/api/docs.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ async fn doc_handler(path: PathBuf, cluster: &Cluster) -> Result<ResponseOk, Sta
5252
.expect("could not parse table of contents markdown");
5353
let guides = markdown::parse_summary_into_nav_links(&mdast)
5454
.expect("could not extract nav links from table of contents");
55-
5655
render(
5756
cluster,
5857
&path,
@@ -137,14 +136,21 @@ async fn render<'a>(
137136
folder: &'a Path,
138137
content: &'a str,
139138
) -> Result<ResponseOk, Status> {
140-
let url = path.clone();
139+
let mut path = path
140+
.to_str()
141+
.expect("path must convert to a string")
142+
.to_string();
143+
let mut url = path.clone();
144+
if path.ends_with("/") {
145+
path.push_str("README");
146+
url.push_str("./");
147+
}
141148

142149
// Get the document content
143150
let path = Path::new(&content)
144151
.join(folder)
145-
.join(&(path.to_str().unwrap().to_string() + ".md"));
152+
.join(&(path.to_string() + ".md"));
146153

147-
info!("path: {:?}", path);
148154
// Read to string
149155
let contents = match tokio::fs::read_to_string(&path).await {
150156
Ok(contents) => contents,
@@ -207,7 +213,7 @@ async fn render<'a>(
207213

208214
// Handle navigation
209215
for nav_link in nav_links.iter_mut() {
210-
nav_link.should_open(&url.to_str().unwrap().to_string());
216+
nav_link.should_open(&url);
211217
}
212218

213219
let user = if cluster.context.user.is_anonymous() {

pgml-dashboard/src/utils/markdown.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,12 @@ pub fn get_sub_links(list: &markdown::mdast::List) -> Result<Vec<NavLink>> {
572572
for node in link.children.iter() {
573573
match node {
574574
markdown::mdast::Node::Text(text) => {
575-
let url =
575+
let mut url =
576576
Path::new(&link.url).with_extension("");
577+
if url.ends_with("README") {
578+
url =
579+
url.parent().unwrap().join("./").into();
580+
}
577581
let url = Path::new("/docs/guides")
578582
.join(url)
579583
.into_os_string()

0 commit comments

Comments
 (0)