Skip to content

rustdoc: move some search code into search.js #84150

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

Merged
merged 7 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,8 @@ pub(super) fn write_shared(
// with rustdoc running in parallel.
all_indexes.sort();
write_crate("search-index.js", &|| {
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
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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 😁

Copy link
Member

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

.replace(r#""SEARCH_INDEX_PLACEHOLDER": {}"#, &all_indexes.join(",\\\n"));
Ok(v.into_bytes())
})?;

Expand Down
Loading