Skip to content
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

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

Closed
pietroalbini opened this issue Jan 17, 2021 · 0 comments · Fixed by #81223
Closed

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

pietroalbini opened this issue Jan 17, 2021 · 0 comments · Fixed by #81223
Assignees
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@pietroalbini
Copy link
Member

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"
}
@pietroalbini pietroalbini added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jan 17, 2021
@GuillaumeGomez GuillaumeGomez self-assigned this Jan 20, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Mar 2, 2021
…p, r=jyn514

[rustdoc] Generate redirect map file

Fixes rust-lang#81134.

So with this code:

```rust
#![crate_name = "foo"]

pub use private::Quz;
pub use hidden::Bar;

mod private {
    pub struct Quz;
}

#[doc(hidden)]
pub mod hidden {
    pub struct Bar;
}

#[macro_export]
macro_rules! foo {
() => {}
}
```

It generates:

```json
{
  "foo/macro.foo!.html": "foo/macro.foo.html",
  "foo/private/struct.Quz.html": "foo/struct.Quz.html",
  "foo/hidden/struct.Bar.html": "foo/struct.Bar.html"
}
```

Do the pathes look as you expected `@pietroalbini?`

r? `@jyn514`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 2, 2021
…p, r=jyn514

[rustdoc] Generate redirect map file

Fixes rust-lang#81134.

So with this code:

```rust
#![crate_name = "foo"]

pub use private::Quz;
pub use hidden::Bar;

mod private {
    pub struct Quz;
}

#[doc(hidden)]
pub mod hidden {
    pub struct Bar;
}

#[macro_export]
macro_rules! foo {
() => {}
}
```

It generates:

```json
{
  "foo/macro.foo!.html": "foo/macro.foo.html",
  "foo/private/struct.Quz.html": "foo/struct.Quz.html",
  "foo/hidden/struct.Bar.html": "foo/struct.Bar.html"
}
```

Do the pathes look as you expected ``@pietroalbini?``

r? ``@jyn514``
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 3, 2021
…p, r=jyn514

[rustdoc] Generate redirect map file

Fixes rust-lang#81134.

So with this code:

```rust
#![crate_name = "foo"]

pub use private::Quz;
pub use hidden::Bar;

mod private {
    pub struct Quz;
}

#[doc(hidden)]
pub mod hidden {
    pub struct Bar;
}

#[macro_export]
macro_rules! foo {
() => {}
}
```

It generates:

```json
{
  "foo/macro.foo!.html": "foo/macro.foo.html",
  "foo/private/struct.Quz.html": "foo/struct.Quz.html",
  "foo/hidden/struct.Bar.html": "foo/struct.Bar.html"
}
```

Do the pathes look as you expected ```@pietroalbini?```

r? ```@jyn514```
@bors bors closed this as completed in 9a827d9 Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants