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

rustdoc: Consolidate static-file replacement mechanism #91062

Merged
merged 3 commits into from
Nov 27, 2021

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Nov 19, 2021

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

@jsha jsha added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: rustdoc UI (generated HTML) labels Nov 19, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 19, 2021
@rust-log-analyzer

This comment has been minimized.

@jyn514 jyn514 changed the title Consolidate static-file replacement mechanism rustdoc: Consolidate static-file replacement mechanism Nov 20, 2021
cx,
options,
)?;

// FIXME: this should probably not be a toolchain file since it depends on `--theme`.
Copy link
Member

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(
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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";
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@jsha
Copy link
Contributor Author

jsha commented Nov 24, 2021

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.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 24, 2021
…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`
Copy link
Member

@jyn514 jyn514 left a 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 :)

@GuillaumeGomez
Copy link
Member

It looks good to me as well, thanks! You'll need to rebase to make the CI happy. ;)

r=jyn514,GuillaumeGomez once done.

@jyn514 jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2021
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).
@jsha
Copy link
Contributor Author

jsha commented Nov 27, 2021

@bors r=jyn514,GuillaumeGomez

@bors
Copy link
Contributor

bors commented Nov 27, 2021

📌 Commit d9afca5 has been approved by jyn514,GuillaumeGomez

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 27, 2021
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Nov 27, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 27, 2021
…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`
This was referenced Nov 27, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 27, 2021
…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
@bors bors merged commit 55f8b5f into rust-lang:master Nov 27, 2021
@rustbot rustbot added this to the 1.59.0 milestone Nov 27, 2021
@jsha jsha deleted the static-file-replace branch November 28, 2021 04:52
@Folyd
Copy link
Contributor

Folyd commented Dec 7, 2021

Ohhh, this PR broke my extension huhu/rust-search-extension#134. 😅
Rust search extension relies on the search-index.js. I hope we can keep the search-index.js loading steadily. Would you mind CC me if the search-index.js loading method has changed? Thanks. ❤️ @jsha @GuillaumeGomez

@jyn514
Copy link
Member

jyn514 commented Dec 7, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: rustdoc UI (generated HTML) 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.

8 participants