Skip to content

Conversation

glazec
Copy link

@glazec glazec commented Aug 9, 2024

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

  • inheritance part: change "/contracts/foo" to "../../../contracts/foo"
  • readme page link for folders( if the contract is inside a subfolder of contract src page, like contracts/consensus/authority/): delete the beginning "/", add some "../", add index.html at the end.
    image
    image

I tested this PR on cartesi/rollups-contracts. You can view the doc website

@glazec
Copy link
Author

glazec commented Aug 13, 2024

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

Comment on lines 451 to 453
.to_string()
.trim_start_matches('/')
.to_string();
Copy link
Member

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?

Copy link
Author

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

Copy link
Author

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?

@glazec glazec requested a review from Evalir August 16, 2024 02:17
@glazec
Copy link
Author

glazec commented Sep 18, 2024

@DaniPopes @mattsse @Evalir Can you review the code?

Comment on lines 448 to 456
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");
Copy link
Member

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.

Copy link
Author

@glazec glazec Sep 21, 2024

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)?;

Comment on lines 448 to 452
let readme_path = Path::new("/")
.join(&path)
.display()
.to_string()
.trim_start_matches('/')
Copy link
Member

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 /

@onbjerg
Copy link
Contributor

onbjerg commented Aug 21, 2025

Closing as per #8576 (comment)

@onbjerg onbjerg closed this Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

bug(forge doc): generated doc contains absolute links, only relative links should be generated bug: forge doc should only generate relative links

6 participants