-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustdoc: Consolidate static-file replacement mechanism #91062
Conversation
Some changes occurred in HTML/CSS/JS. |
This comment has been minimized.
This comment has been minimized.
cx, | ||
options, | ||
)?; | ||
|
||
// FIXME: this should probably not be a toolchain file since it depends on `--theme`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this FIXME now I think :)
cx, | ||
options, | ||
)?; | ||
|
||
// FIXME: this should probably not be a toolchain file since it depends on `--theme`. | ||
// But it seems a shame to copy it over and over when it's almost always the same. | ||
// Maybe we can change the representation to move this out of main.js? | ||
write_minify( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think this should be using cx.write_minify(InvocationSpecific)
, since it can vary from crate to crate. Unfortunately we don't have a good way of testing this before it hits nightly right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that is invocation specific is the list of themes, right? What if I put those in a data-
attribute in the HTML instead? The list is quite short, so duplication is not a big concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great! Thanks :)
@@ -1,5 +1,8 @@ | |||
// From rust: | |||
/* global resourcesSuffix */ | |||
var resourcesSuffix = /* AUTOREPLACE: */"RESOURCE_SUFFIX"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried about this: if we generate docs with two different rustdoc version and/or different suffix, it means the older version will use newer files, which might break the display.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storage is stored as a versioned file (e.g. storage1.58.0.js), so it would load the other versioned files that match it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, if you use suffix, otherwise you'll simply overwrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible for rustdoc alone to prevent conflicting versions with our current setup. If you think that should be a goal, maybe open an issue or MCP but I don't think it makes sense to hold specific parts of rustdoc to a higher standard than others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I think about it, the more I think it would be cleaner to put each of these three variables in a data-
attribute in the HTML, like I proposed in #91062 (comment). The big advantage there is that when you're editing JS you can copy it directly into place without waiting to rebuild rustdoc. I've run into this a number of times just recently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible for rustdoc alone to prevent conflicting versions with our current setup. If you think that should be a goal, maybe open an issue or MCP but I don't think it makes sense to hold specific parts of rustdoc to a higher standard than others.
It is working currently because the links are set directly in the HTML, not in the JS which is regenerated. This is my biggest issue with this change, moving "hard-coded" HTML content into JS.
@jsha Yes, I think that could work. The added size would be negligible as well.
b424fd8
to
7a5cd2b
Compare
Alright, I switched this up so that main.js isn't rewritten at all - instead, the variables we want are set in the rustdoc-vars div. One big change along the way: I revamped how stylesheets links are rendered into the HTML (c330963). I think this cleans things up a lot. It also made it much nicer to be able to generate a list of themes in layout.rs. Also I changed storage.js to not rely on resource_suffix, because rustdoc-vars aren't yet available at the time storage.js runs. |
This comment has been minimized.
This comment has been minimized.
7a5cd2b
to
276ea81
Compare
This comment has been minimized.
This comment has been minimized.
276ea81
to
57e6fd7
Compare
…eGomez Fix toggle-click-deadspace rustdoc-gui test In rust-lang#91103 I introduced a rustdoc-gui test for clicks on toggles. I introduced some documentation on a method in lib2/struct.Foo.html so there would be something to toggle, but accidentally left the test checking test_docs/struct.Foo.html. That caused the test to reliably fail. I'm not sure how that test got past GitHub Actions and bors, but it's manifesting in test failures at rust-lang#91062 (comment) and rust-lang#91170 (comment). This fixes by pointing at the right file. r? `@GuillaumeGomez`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I want to give Guillaume a chance to review. Thanks for working on this :)
It looks good to me as well, thanks! You'll need to rebase to make the CI happy. ;) r=jyn514,GuillaumeGomez once done. |
We carry around a list of stylesheets that can carry two different types of thing: 1. Internal stylesheets specific to a page type (only for settings) 2. Themes In this change I move the link generation for settings.css into settings(), so Context.style_files is reserved just for themes. We had two places where we extracted a base theme name from a list of StylePaths. I consolidated that code to be a method on StylePath. I moved generation of link tags for stylesheets into the page.html template. With that change, I made the template responsible for special handling of light.css (making it the default theme) and of the other themes (marking them disabled). That allowed getting rid of the `disabled` field on StylePath.
We had been injecting the list of themes and the rustdoc version into main.js by rewriting it at doc generation time. By avoiding this rewrite, we can make it easier to edit main.js without regenerating all the docs. Added a more convenient accessor for rustdoc-vars. Changed storage.js to not rely on resourcesSuffix. It could in theory use rustdoc-vars, but because rustdoc-vars is at the end of the HTML, it's not available when storage.js runs (very early in page load).
57e6fd7
to
d9afca5
Compare
@bors r=jyn514,GuillaumeGomez |
📌 Commit d9afca5 has been approved by |
…GuillaumeGomez rustdoc: Consolidate static-file replacement mechanism There were a few places in rustdoc where we would take static JS or CSS and rewrite it at doc generation time to insert values. This consolidates all the CSS instances into one CSS file and replaces the JS examples with data- attributes on the rustdoc-vars div. Demo https://rustdoc.crud.net/jsha/static-file-replace/test_docs/ r? `@GuillaumeGomez`
…askrgr Rollup of 6 pull requests Successful merges: - rust-lang#83791 (Weaken guarantee around advancing underlying iterators in zip) - rust-lang#90995 (Document non-guarantees for Hash) - rust-lang#91057 (Expand `available_parallelism` docs in anticipation of cgroup quota support) - rust-lang#91062 (rustdoc: Consolidate static-file replacement mechanism) - rust-lang#91208 (Account for incorrect `where T::Assoc = Ty` bound) - rust-lang#91266 (Use non-generic inner function for pointer formatting) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Ohhh, this PR broke my extension huhu/rust-search-extension#134. 😅 |
@Folyd you can set up an automatic ping in the highfive bot if you like - here's an example: https://github.com/rust-lang/highfive/blob/6e2c21639aaeafaeae423b244d353247c507d46a/highfive/configs/rust-lang/rust.json#L134 |
Ping @Folyd if some changes occurred in librustdoc's HTML/CSS/JS. Related context: rust-lang/rust#91062 (comment)
There were a few places in rustdoc where we would take static JS or CSS and rewrite it at doc generation time to insert values. This consolidates all the CSS instances into one CSS file and replaces the JS examples with data- attributes on the rustdoc-vars div.
Demo https://rustdoc.crud.net/jsha/static-file-replace/test_docs/
r? @GuillaumeGomez