-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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: move some search code into search.js #84150
Conversation
Export a few variables and functions into the global scope because they are needed both by main.js and search-index.js.
Some changes occurred in HTML/CSS/JS. |
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This allows sharing across main.js and search.js without exporting too many symbols into the global namespace.
let mut v = String::from("var searchIndex = JSON.parse('{\\\n"); | ||
v.push_str(&all_indexes.join(",\\\n")); | ||
v.push_str("\\\n}');\ninitSearch(searchIndex);"); | ||
let v = static_files::SEARCH_JS |
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.
Please don't make this change! search-index.js
is only supposed to contain the search "content", nothing else. Create a new JS file or insert the content into main.js
but don't change how we handle search-index.js
.
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.
Ok! Happy to split this out into search.js
. Why is search-index.js
supposed to only contain the search content and nothing else?
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.
Multiple reason: this is a file different for every crate, meaning that docs.rs cannot store it once and for all. Also it's faster to parse a smaller file (even if here, the part you add might not be that big compared to the search index itself).
So here, it's mostly for docs.rs reason.
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.
And for docs.rs it would be nice to convert it to .json
at some point 😁
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.
Not possible as is unfortunately, you can load json files for local docs. :3
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The end result is very nice, thanks a lot! Just one thing to check first: @rust-lang/docs-rs there is new static JS file added. iirc, there is nothing to be done anymore on docs.rs side now but just want to check before approving this PR. |
Yes, that's fine. You don't need to keep pinging :) |
Promise, it was the last time! :) |
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
Thanks for the review! Should I rebase? |
@jsha no need, the PR doesn't have conflicts. If people had to rebase on every merge we'd never get any PR merged 😆 |
Thanks! r=me once the CI is happy. (If you want to rebase, no one will stop you, but it's not required as @jyn514 explained ;) ) |
Looks like CI is done. :-) |
@bors r=GuillaumeGomez |
📌 Commit 6f1f3eb has been approved by |
Rollup of 4 pull requests Successful merges: - rust-lang#83237 (rustdoc: use more precise relative URLs) - rust-lang#84150 (rustdoc: move some search code into search.js) - rust-lang#84203 (rustdoc: Give a more accurate span for anchor failures) - rust-lang#84257 (Add documentation to help people find `Ipv4Addr::UNSPECIFIED`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…tate-focus, r=GuillaumeGomez docs: fix broken link "search bar" Regression introduced by rust-lang#84150
This reduces main.s from 3094 lines to 1587. Also it saves some bytes
of download in the case where search isn't used.
There were a fair number of variables that needed to be accessible in
both main.js and search.js, but I didn't want to put too many symbols in
the global namespace, so I consolidated much of the search-related
state and functions into a new object
window.searchState
.Demo at https://hoffman-andrews.com/rust/move-search/std/?search=foo