-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add support for repository-path in forge doc #10879
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
base: master
Are you sure you want to change the base?
feat: add support for repository-path in forge doc #10879
Conversation
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.
Thank you, left a comment. Also please fix fmt and undo Cargo.lock updates, don't think they are needed?
crates/doc/src/builder.rs
Outdated
Some(dir) => { | ||
// If directory is specified, append it to the repository URL | ||
let repo_clean = repo.trim_end_matches('/'); | ||
format!("{}/tree/main/{}", repo_clean, dir.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 won't work for repos with default branch master (or other), maybe directory
option should be renamed to path
or repo_path
) and should contain exact value (like directory = "main/packages/contracts"
or directory = "tree/main/packages/contracts"
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.
Should I add a separate configuration option for the branch, or simply rename directory to path and let users specify the full path, including the branch?
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.
I suggest renaming and make description clear on what's expected. Thank you
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.
I have made the change as you said
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.
Nice, thank you, please add description for the new option.
…nd undo Cargo.lock
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.
smol nit
@@ -20,6 +20,8 @@ pub struct DocConfig { | |||
/// The repository url. | |||
#[serde(default, skip_serializing_if = "Option::is_none")] | |||
pub repository: Option<String>, | |||
#[serde(default, skip_serializing_if = "Option::is_none")] |
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.
can we add a oneliner doc 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.
yeah!
// Create the full repository URL | ||
let git_repo_url = match &self.config.path { | ||
Some(path) => { | ||
// If path is specified, append it to the repository URL | ||
let repo_clean = repo.trim_end_matches('/'); | ||
format!("{}/{}", repo_clean, dir.trim_start_matches('/')) | ||
} | ||
None => { | ||
// No path specified, use repository URL as-is | ||
repo.clone() | ||
} | ||
}; |
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 makes sense,
I'd prefer a if let some else
style here instead of the match
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.
Thanks mattsse! going to do it !
Motivation
When working with monorepos or projects where source code is located in specific directories, documentation links should point directly to the relevant code location rather than the repository root. This improves developer experience by providing direct navigation to the actual source files.
Solution
Added an optional
path
configuration field to the[doc]
section that allows specifying the exact repository path for documentation links. This field accepts the full path including branch information, providing flexibility for repositories with different default branches.Configuration
Result
Documentation links now point to:
Key Features
main
,master
,develop
, etc.)Usage Examples
This change enables accurate source code navigation from documentation, particularly valuable in monorepo setups and projects with non-standard repository structures.
Fixes #10836