-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Change absolute link to relative link during doc generation #8641
base: master
Are you sure you want to change the base?
Conversation
I saw the CI failed. The failed part is on anvil, but my commit is about doc part. Anyone can help me review it? @DaniPopes |
crates/doc/src/builder.rs
Outdated
.to_string() | ||
.trim_start_matches('/') | ||
.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any chance we can avoid the double allocation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to_string to to_owned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Evalir Can you check the fix?
@DaniPopes @mattsse @Evalir Can you review the code? |
crates/doc/src/builder.rs
Outdated
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, unclear what this does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattsse Thanks for the comment. I optimized the code in the new commit. The code here transform the path into a relative path which can be used in a web server.
// Generate a relative path to "index.html" based on the current directory depth and
let name = path.iter().last().unwrap().to_string_lossy();
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)?;
crates/doc/src/builder.rs
Outdated
let readme_path = Path::new("/") | ||
.join(&path) | ||
.display() | ||
.to_string() | ||
.trim_start_matches('/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this step seems redundant because we first join then remove the leading /
Motivation
Closes #8576 This issue found a link problem in forge doc generated website. Some link uses the absolute link like /contracts/foo which is an invalid URL.
Solution
There are two parts using the wrong absolute link
"/contracts/foo"
to"../../../contracts/foo"
contracts/consensus/authority/
): delete the beginning"/"
, add some"../"
, addindex.html
at the end.I tested this PR on cartesi/rollups-contracts. You can view the doc website