-
Notifications
You must be signed in to change notification settings - Fork 13.6k
rustdoc: add doc_link_canonical feature #143158
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?
rustdoc: add doc_link_canonical feature #143158
Conversation
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
50577b1
to
0a25ca7
Compare
The one feature that isn't currently implemented is having the default value be the same as from |
This comment has been minimized.
This comment has been minimized.
Took a look at the implementation, it seems correct. However, I'm not sure it solves it the correct way, would need to actually completely understand the issue (don't have time right now but didn't want to leave the PR pending with no feedback). So for experimental features, we generally go through an FCP. Now, to make a PR able to go through FCP, the first comment needs to contain a lot more information: describe exactly the problem it tries to solve, how it solved it and why it solved it this way. |
@GuillaumeGomez did my best to describe the experiment, let me know if there's anything I can give more details on or write better. |
☔ The latest upstream changes (presumably #144181) made this pull request unmergeable. Please resolve the merge conflicts. |
Thanks for the complete explanations. Time to start the fcp then. :) @rfcbot fcp merge |
This comment was marked as off-topic.
This comment was marked as off-topic.
Woops, too many teams pinged. Sorry for the notifications... @rfcbot fcp cancel |
@GuillaumeGomez proposal cancelled. |
@rfcbot fcp merge |
Team member @GuillaumeGomez has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Based on what I've seen discussed in rust-lang/docs.rs#1438 I think there's a double-bind if you try to do that.
So I don't think you can actually used it for that. |
@notriddle couldn't you gate the attribute behind ofc, that would either have to wait for stabilization, or it would require a seperate nightly feature, so it wouldn't be a perfect solution. |
The problem isn't with linking from docs.rs. The problem is linking to docs.rs. There's no URL to point at that simultaneously satisfies the rel="canonical" law and the team's SEO goals. Outside of docs.rs, you've still got the same core problem: you have to make sure that the page you link to has the same crate version, not just the same name, or Google will ignore the link. Other than docs.rs and doc.rust-lang.org, most sites have no way to do that, because they don't have version numbers in their URLs. |
proposing this as a t-rustdoc experiment (do we have a process for those?), implementation was surprisingly simple so it's basically a complete implementation of my design (although ideally it would be integrated into cargo in the future using
--crate-attr
), will likely need FCP then RFC for stabilization, may also need perf testing to make sure added allocations have a negligible impact, not sure.fixes #143139
r? @GuillaumeGomez
Problem Statement
There are two main usecases for this feature:
docs.rs
.docs.rs
be their canonical documentation site, but their crate docs are frequently included in doc bundles hosted by a third party.In both these cases, this can cause search engines to duplicate results or show the wrong (non-canonical) page in results.
Solution
A new crate-level doc attribute is added,
html_link_canonical
, which adds alink rel="canonical"
element to the head of every documentation page (pages such as help and settings are excluded due to not belonging to any crate in particular), leveraging the existing system search engines use for de-duplicating equivalent pages.Future Work
html_link_canonical
is used with no value, it will use the value ofhtml_root_url
, or--extern-html-root-url
, if present.cargo
flag that implies-Zrustdoc-map
and passes--crate-attr='doc(html_link_canonical)'
to each rustdoc invocation. This will cause all crates that do not manually specifyhtml_root_url
orhtml_link_canonical
to use thedocs.rs
page as the canonical page. Alternatively, instead of implying-Zrustdoc-map
, it could simply reuse its logic, passing the value that would be passed to--extern-html-root-url
to be passed via--crate-attr='doc(html_link_canonical="...")'
.