Skip to content

Add a flag to generate a redirect map in rustdoc #81134

Closed
@pietroalbini

Description

@pietroalbini

Rustdoc needs redirects in the output it produces, for example when an item is publicly re-exported. Currently redirects are implemented by generating HTML pages like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="refresh" content="0;URL=../../example/struct.Public.html">
</head>
<body>
    <p>Redirecting to <a href="../../example/struct.Public.html">../../example/struct.Public.html</a>...</p>
    <script>location.replace("../../example/struct.Public.html" + location.search + location.hash);</script>
</body>
</html>

The problem with this approach is that the user sees the HTML page for a brief moment of time while the redirect is performed, which is not really a great UX. The HTML page also includes an inline <script> tag, which makes implementing content security policies harder. Still, this is the only way to implement redirects when the user visits documentation from the local filesystem or a static web server.

Dynamic applications like docs.rs can provide a better UX than this though, by performing the redirects on the server side. This issue proposes a new -Z generate-redirect-map unstable flag, which stops generating HTML redirects and instead produces a redirect-map.json file at the top level containing all the redirects needed by rustdoc:

{
    "example/private/struct.Public.html": "example/struct.Public.html"
}

Metadata

Metadata

Labels

C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions