Skip to content

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

Conversation

ThePuzzlemaker
Copy link
Contributor

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!)

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

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!)
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 20, 2021
@ThePuzzlemaker
Copy link
Contributor Author

@rustbot modify labels: +T-rustdoc

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 20, 2021
@GuillaumeGomez
Copy link
Member

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...

@ThePuzzlemaker
Copy link
Contributor Author

ThePuzzlemaker commented Jan 20, 2021

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:
https://github.com/rust-lang/cargo/blob/a73e5b7d567c3036b296fc6b33ed52c5edcd882e/src/cargo/ops/cargo_doc.rs#L83-L86

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.

@ThePuzzlemaker
Copy link
Contributor Author

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.

@jyn514
Copy link
Member

jyn514 commented Jan 20, 2021

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...

@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.

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 don't see how this breaks anything. They still all link to the logo redirect, which is updated whenever you document any crate.

@GuillaumeGomez
Copy link
Member

Because then it doesn't redirect to the "main" crate but to the last documented.

@jyn514
Copy link
Member

jyn514 commented Jan 21, 2021

Ok, if you think this is the wrong approach we'll have to add a rustdoc flag and get cargo to start passing it.

@jyn514 jyn514 closed this Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants