From 5fd85dcecdb5d0de02b59d3a664a078023e81aa1 Mon Sep 17 00:00:00 2001
From: glaze
Date: Fri, 9 Aug 2024 18:47:38 -0400
Subject: [PATCH 1/4] change inherits link to relative link
---
crates/doc/src/writer/as_doc.rs | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/crates/doc/src/writer/as_doc.rs b/crates/doc/src/writer/as_doc.rs
index a21a59c1111c4..c98d543169e90 100644
--- a/crates/doc/src/writer/as_doc.rs
+++ b/crates/doc/src/writer/as_doc.rs
@@ -146,8 +146,16 @@ impl AsDoc for Document {
.ok()
.unwrap_or(path),
);
- Markdown::Link(&base_doc, &path.display().to_string())
- .as_doc()
+ Markdown::Link(
+ &base_doc,
+ &format!(
+ "../../../{}",
+ path.display()
+ .to_string()
+ .trim_start_matches('/')
+ ),
+ )
+ .as_doc()
})
})
.transpose()?
From 73e05ab0064dfa2edbcc2a0f359646ce392fd261 Mon Sep 17 00:00:00 2001
From: glaze
Date: Fri, 9 Aug 2024 18:47:51 -0400
Subject: [PATCH 2/4] change readme link to relative link
---
crates/doc/src/builder.rs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/crates/doc/src/builder.rs b/crates/doc/src/builder.rs
index e21e80c22bd5b..806f57e7f0ef1 100644
--- a/crates/doc/src/builder.rs
+++ b/crates/doc/src/builder.rs
@@ -445,7 +445,15 @@ impl DocBuilder {
}
} else {
let name = path.iter().last().unwrap().to_string_lossy();
- let readme_path = Path::new("/").join(&path).display().to_string();
+ let readme_path = Path::new("/")
+ .join(&path)
+ .display()
+ .to_string()
+ .trim_start_matches('/')
+ .to_string();
+ let slash_count = readme_path.chars().filter(|&c| c == '/').count();
+ let prefix = "../".repeat(slash_count);
+ let readme_path = format!("{prefix}{readme_path}/index.html");
readme.write_link_list_item(&name, &readme_path, 0)?;
self.write_summary_section(summary, &files, Some(&path), depth + 1)?;
}
From c862b323a7e834239e87b6dfd6cf5be320b911a0 Mon Sep 17 00:00:00 2001
From: glaze
Date: Thu, 15 Aug 2024 12:35:56 -0400
Subject: [PATCH 3/4] Fixe double allocation problem
---
crates/doc/src/builder.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crates/doc/src/builder.rs b/crates/doc/src/builder.rs
index 806f57e7f0ef1..7c16fdfae7b15 100644
--- a/crates/doc/src/builder.rs
+++ b/crates/doc/src/builder.rs
@@ -450,7 +450,7 @@ impl DocBuilder {
.display()
.to_string()
.trim_start_matches('/')
- .to_string();
+ .to_owned();
let slash_count = readme_path.chars().filter(|&c| c == '/').count();
let prefix = "../".repeat(slash_count);
let readme_path = format!("{prefix}{readme_path}/index.html");
From 782e73a791d629f851e2b53eed625205e44c304f Mon Sep 17 00:00:00 2001
From: glaze
Date: Fri, 20 Sep 2024 22:13:19 -0400
Subject: [PATCH 4/4] optimize the code
---
crates/doc/src/builder.rs | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/crates/doc/src/builder.rs b/crates/doc/src/builder.rs
index 7c16fdfae7b15..a958a6313f561 100644
--- a/crates/doc/src/builder.rs
+++ b/crates/doc/src/builder.rs
@@ -444,17 +444,16 @@ impl DocBuilder {
readme.write_link_list_item(ident, &readme_path.display().to_string(), 0)?;
}
} else {
+ // Generate a relative path to "index.html" based on the current directory depth and
let name = path.iter().last().unwrap().to_string_lossy();
- let readme_path = Path::new("/")
- .join(&path)
- .display()
- .to_string()
- .trim_start_matches('/')
- .to_owned();
- let slash_count = readme_path.chars().filter(|&c| c == '/').count();
- let prefix = "../".repeat(slash_count);
- let readme_path = format!("{prefix}{readme_path}/index.html");
- readme.write_link_list_item(&name, &readme_path, 0)?;
+ let depth = path.components().count();
+ let mut prefix = PathBuf::new();
+ for _ in 0..depth {
+ prefix.push("..");
+ }
+ let readme_path = prefix.join(&path).join("index.html");
+ let readme_path_str = readme_path.to_string_lossy();
+ readme.write_link_list_item(&name, &readme_path_str, 0)?;
self.write_summary_section(summary, &files, Some(&path), depth + 1)?;
}
}