-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Redirect to "main crate" when clicking Rust logo (or custom logo) #81203
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
Redirect to "main crate" when clicking Rust logo (or custom logo) #81203
Conversation
The "main crate" in this case would be the one that is opened by `cargo doc --open` by default. However, since doing this on cargo's end would require a lot more work, @jyn514 recommended a hacky solution that works. This solution is to create a redirect page (called `logo-redirect.html`) in the documentation root directory when documenting a crate. Thus, the last crate documented (usually a binary or the main library) is the one redirected to by this file. This file is then pointed to by the logo. Note that as jynelson noted: > this assumes you never document examples, and that if you > document a binary, you want it to take precedence over the library I'm pretty sure this is probably the desired behaviour (and I don't think that examples are documented during `cargo doc`), so this hack should probably work for now. (And that's how programming works!)
@rustbot modify labels: +T-rustdoc |
In many cases, you can simply have multiple crates in a same workspace. I don't see how this could work nicely in this case... |
Hm, yeah, this does not work favorably when using workspaces without an executable crate. We might have to go the long way and pass it in through cargo. This is where the "main crate"'s name is obtained: I was thinking that we could add a new flag that passes this information into rustdoc but instead of having to do all the stuff with modifying both rustdoc and cargo and possibly stabilization, jynelson suggested this hack. I'm not really sure how we can fix this though, without having to go through both rustdoc and cargo. |
Also noticed another problem: if the list of crates changes (e.g. Cargo.toml is updated with new workspace members), the entire crate list is not re-documented so the logo redirect may become out of date. I think we might just have to do this the harder way. |
@GuillaumeGomez that's exactly what this is designed for: if there are multiple crates, they will all link to the same redirect, but only the last redirect written to disk will have an effect. So it will be as if they all link to the last crate documented.
I don't see how this breaks anything. They still all link to the logo redirect, which is updated whenever you document any crate. |
Because then it doesn't redirect to the "main" crate but to the last documented. |
Ok, if you think this is the wrong approach we'll have to add a rustdoc flag and get cargo to start passing it. |
The "main crate" in this case would be the one that is opened by
cargo doc --open
by default. However, since doing this on cargo's end would require a lot more work, @jyn514 recommended a hacky solution that works. This solution is to create a redirect page (calledlogo-redirect.html
) in the documentation root directory when documenting a crate. Thus, the last crate documented (usually a binary or the main library) is the one redirected to by this file. This file is then pointed to by the logo.Note that as jynelson noted:
I'm pretty sure this is probably the desired behaviour (and I don't think that examples are documented during
cargo doc
), so this hack should probably work for now. (And that's how programming works!)This PR fixes part of #81031. (The other part is a larger project that I'm going to work on for a bit)
r? @jyn514