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

Rewrite error index generator to greatly reduce the size of the pages #100922

Merged
merged 3 commits into from
Aug 24, 2022

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Aug 23, 2022

Fixes #100736.

Instead of having all error codes in a same page (making the DOM way too big), I split the output into multiple files and generated a list of links (if there is an explanation) to the error codes' explanation into the already existing file.

I also used this opportunity to greatly simplify the code. Instead of needing a build.rs, I simply imported the file we want and wrote the macro which generates a function containing everything we need. We just need to call it to get the error codes and their explanation (if any). Also, considering the implementations between markdown and HTML formats differed even further, the Formatter trait was becoming too problematic so I removed it too.

You can test it here.

cc @jsha
r? @notriddle

@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-error-codes Area: Explanation of an error code (--explain) labels Aug 23, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 23, 2022
@notriddle
Copy link
Contributor

I think this is a good idea. Can we add a JavaScript gizmo to redirect https://doc.rust-lang.org/nightly/error-index.html#E0599 to https://doc.rust-lang.org/nightly/error_codes/E0599.html? There's going to be a lot of links to the previous version floating around, and I don't want to break all of them.

It should absolutely be inline in the <head>, since it won't be very big and we want the redirect to be processed without the rest of the page showing up.

<script>(function() {
    if (window.location.hash) {
        let code = window.location.hash.replace(/^#/, "");
        // We have to make sure this pattern matches to avoid inadvertently creating an open redirect.
        if (/^E[0-9]+$/.test(code)) {
            window.location = "./error_codes/" + code + ".html";
        }
    }
})()</script>

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

The CI just confirmed your thought actually. I completely overlooked that. I'll send an update shortly.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Aug 23, 2022

I added the JS you provided which does exactly what it should (thanks!) and I fixed the two broken URLs.

EDIT: And also updated the online demo.

@notriddle
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 24, 2022

📌 Commit 4398d92 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 24, 2022
…, r=notriddle

Rewrite error index generator to greatly reduce the size of the pages

Fixes rust-lang#100736.

Instead of having all error codes in a same page (making the DOM way too big), I split the output into multiple files and generated a list of links (if there is an explanation) to the error codes' explanation into the already existing file.

I also used this opportunity to greatly simplify the code. Instead of needing a `build.rs`, I simply imported the file we want and wrote the macro which generates a function containing everything we need. We just need to call it to get the error codes and their explanation (if any). Also, considering the implementations between markdown and HTML formats differed even further, the `Formatter` trait was becoming too problematic so I removed it too.

You can test it [here](https://rustdoc.crud.net/imperio/rewrite-error-index/error-index.html).

cc `@jsha`
r? `@notriddle`
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 24, 2022
…iaskrgr

Rollup of 15 pull requests

Successful merges:

 - rust-lang#99993 (linker: Update some outdated comments)
 - rust-lang#100220 (Properly forward `ByRefSized::fold` to the inner iterator)
 - rust-lang#100826 (sugg: take into count the debug formatting)
 - rust-lang#100855 (Extra documentation for new formatting feature)
 - rust-lang#100888 (Coherence negative impls implied bounds)
 - rust-lang#100901 (Make some methods private)
 - rust-lang#100906 (Suggest alternatives when trying to mutate a `HashMap`/`BTreeMap` via indexing)
 - rust-lang#100912 (Diagnose missing includes in run-make tests)
 - rust-lang#100919 (Use par_body_owners for liveness)
 - rust-lang#100922 (Rewrite error index generator to greatly reduce the size of the pages)
 - rust-lang#100926 (Update README.md)
 - rust-lang#100930 (Use `--userns=keep-id` when "docker" is really podman)
 - rust-lang#100938 (rustdoc: remove unused CSS rule)
 - rust-lang#100940 (Do not suggest adding a bound to a opaque type)
 - rust-lang#100945 (Add a missing test case for impl generic mismatch)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fe1f1f1 into rust-lang:master Aug 24, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 24, 2022
@GuillaumeGomez GuillaumeGomez deleted the rewrite-error-index branch August 25, 2022 08:51
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 2, 2022
… r=notriddle

Generate error index with mdbook instead of raw HTML pages

This is a follow-up of rust-lang#100922.

This comes from a remark from `@estebank` who said that the search was a nice thing on the previous version and that it wasn't possible anymore. An easy way to come around this limitation was to use `mdbook`, which is what I did here.

Now some explanations on the code. I'll explain how I developed this and why I reached this solution. First I did it very basically by simply setting the source directory and the output directory, generated a `SUMMARY.md` manually which listed all error codes and that was it. Two problems arose from this:
 1. A lot of new HTML files were generated at the top level
 2. An `index.html` file was generated at the top-level (the summary in short).

So for `1.`, it's not great to have too many files at the top-level as it could create file conflicts more easily. And for `2.`, this is actually a huge issue because <doc.rust-lang.org> generates an `index.html` file with a links to a few different resources, so it should never be overwritten. <s>Unfortunately, `mdbook` **always** generates an `index.html` file so the only solution I could see (except for sending them a contribution, I'll maybe do that later) was to temporaly move a potentially existing `index.html` file and then puts it back once done. For this last part, to ensure that we don't return *before* it has been put back, I wrapped the `mdbook` generation code inside `render_html_inner` which is called from `render_html` which in turn handle the "save" of `index.html`.</s>

EDIT: `mdbook` completely deletes ALL the content in the target directory so I instead generate into a sub directory and then I move the files to the real target directory.

To keep compatibility with the old version, I also put the `<script>` `@notriddle` nicely provided in the previous PR only into the `error-index.html` file to prevent unneeded repetition. I didn't use `mdbook` `additional-js` option because the JS is included at the end of all HTML files, which we don't want for two reasons:
 1. It's slow.
 2. We only want it to be run in `error-index.html` (even if we also ensure in the JS itself too!).

<s>Now the last part: why we generate the summary twice. We actually generate it once to tell `mdbook` what the book will look like and a second time because a create a new chapter content which will actually list all the error codes (with the updated paths).</s>

EDIT: I removed the need for two summaries.

You can test it [here](https://rustdoc.crud.net/imperio/error-index-mdbook/error-index.html).

r? `@notriddle`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 2, 2022
… r=notriddle

Generate error index with mdbook instead of raw HTML pages

This is a follow-up of rust-lang#100922.

This comes from a remark from ``@estebank`` who said that the search was a nice thing on the previous version and that it wasn't possible anymore. An easy way to come around this limitation was to use `mdbook`, which is what I did here.

Now some explanations on the code. I'll explain how I developed this and why I reached this solution. First I did it very basically by simply setting the source directory and the output directory, generated a `SUMMARY.md` manually which listed all error codes and that was it. Two problems arose from this:
 1. A lot of new HTML files were generated at the top level
 2. An `index.html` file was generated at the top-level (the summary in short).

So for `1.`, it's not great to have too many files at the top-level as it could create file conflicts more easily. And for `2.`, this is actually a huge issue because <doc.rust-lang.org> generates an `index.html` file with a links to a few different resources, so it should never be overwritten. <s>Unfortunately, `mdbook` **always** generates an `index.html` file so the only solution I could see (except for sending them a contribution, I'll maybe do that later) was to temporaly move a potentially existing `index.html` file and then puts it back once done. For this last part, to ensure that we don't return *before* it has been put back, I wrapped the `mdbook` generation code inside `render_html_inner` which is called from `render_html` which in turn handle the "save" of `index.html`.</s>

EDIT: `mdbook` completely deletes ALL the content in the target directory so I instead generate into a sub directory and then I move the files to the real target directory.

To keep compatibility with the old version, I also put the `<script>` ``@notriddle`` nicely provided in the previous PR only into the `error-index.html` file to prevent unneeded repetition. I didn't use `mdbook` `additional-js` option because the JS is included at the end of all HTML files, which we don't want for two reasons:
 1. It's slow.
 2. We only want it to be run in `error-index.html` (even if we also ensure in the JS itself too!).

<s>Now the last part: why we generate the summary twice. We actually generate it once to tell `mdbook` what the book will look like and a second time because a create a new chapter content which will actually list all the error codes (with the updated paths).</s>

EDIT: I removed the need for two summaries.

You can test it [here](https://rustdoc.crud.net/imperio/error-index-mdbook/error-index.html).

r? ``@notriddle``
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 2, 2022
… r=notriddle

Generate error index with mdbook instead of raw HTML pages

This is a follow-up of rust-lang#100922.

This comes from a remark from ```@estebank``` who said that the search was a nice thing on the previous version and that it wasn't possible anymore. An easy way to come around this limitation was to use `mdbook`, which is what I did here.

Now some explanations on the code. I'll explain how I developed this and why I reached this solution. First I did it very basically by simply setting the source directory and the output directory, generated a `SUMMARY.md` manually which listed all error codes and that was it. Two problems arose from this:
 1. A lot of new HTML files were generated at the top level
 2. An `index.html` file was generated at the top-level (the summary in short).

So for `1.`, it's not great to have too many files at the top-level as it could create file conflicts more easily. And for `2.`, this is actually a huge issue because <doc.rust-lang.org> generates an `index.html` file with a links to a few different resources, so it should never be overwritten. <s>Unfortunately, `mdbook` **always** generates an `index.html` file so the only solution I could see (except for sending them a contribution, I'll maybe do that later) was to temporaly move a potentially existing `index.html` file and then puts it back once done. For this last part, to ensure that we don't return *before* it has been put back, I wrapped the `mdbook` generation code inside `render_html_inner` which is called from `render_html` which in turn handle the "save" of `index.html`.</s>

EDIT: `mdbook` completely deletes ALL the content in the target directory so I instead generate into a sub directory and then I move the files to the real target directory.

To keep compatibility with the old version, I also put the `<script>` ```@notriddle``` nicely provided in the previous PR only into the `error-index.html` file to prevent unneeded repetition. I didn't use `mdbook` `additional-js` option because the JS is included at the end of all HTML files, which we don't want for two reasons:
 1. It's slow.
 2. We only want it to be run in `error-index.html` (even if we also ensure in the JS itself too!).

<s>Now the last part: why we generate the summary twice. We actually generate it once to tell `mdbook` what the book will look like and a second time because a create a new chapter content which will actually list all the error codes (with the updated paths).</s>

EDIT: I removed the need for two summaries.

You can test it [here](https://rustdoc.crud.net/imperio/error-index-mdbook/error-index.html).

r? ```@notriddle```
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 2, 2022
… r=notriddle

Generate error index with mdbook instead of raw HTML pages

This is a follow-up of rust-lang#100922.

This comes from a remark from ````@estebank```` who said that the search was a nice thing on the previous version and that it wasn't possible anymore. An easy way to come around this limitation was to use `mdbook`, which is what I did here.

Now some explanations on the code. I'll explain how I developed this and why I reached this solution. First I did it very basically by simply setting the source directory and the output directory, generated a `SUMMARY.md` manually which listed all error codes and that was it. Two problems arose from this:
 1. A lot of new HTML files were generated at the top level
 2. An `index.html` file was generated at the top-level (the summary in short).

So for `1.`, it's not great to have too many files at the top-level as it could create file conflicts more easily. And for `2.`, this is actually a huge issue because <doc.rust-lang.org> generates an `index.html` file with a links to a few different resources, so it should never be overwritten. <s>Unfortunately, `mdbook` **always** generates an `index.html` file so the only solution I could see (except for sending them a contribution, I'll maybe do that later) was to temporaly move a potentially existing `index.html` file and then puts it back once done. For this last part, to ensure that we don't return *before* it has been put back, I wrapped the `mdbook` generation code inside `render_html_inner` which is called from `render_html` which in turn handle the "save" of `index.html`.</s>

EDIT: `mdbook` completely deletes ALL the content in the target directory so I instead generate into a sub directory and then I move the files to the real target directory.

To keep compatibility with the old version, I also put the `<script>` ````@notriddle```` nicely provided in the previous PR only into the `error-index.html` file to prevent unneeded repetition. I didn't use `mdbook` `additional-js` option because the JS is included at the end of all HTML files, which we don't want for two reasons:
 1. It's slow.
 2. We only want it to be run in `error-index.html` (even if we also ensure in the JS itself too!).

<s>Now the last part: why we generate the summary twice. We actually generate it once to tell `mdbook` what the book will look like and a second time because a create a new chapter content which will actually list all the error codes (with the updated paths).</s>

EDIT: I removed the need for two summaries.

You can test it [here](https://rustdoc.crud.net/imperio/error-index-mdbook/error-index.html).

r? ````@notriddle````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-error-codes Area: Explanation of an error code (--explain) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

error-index is slow to load and shows docs for wrong item while loading
6 participants