diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-04-26 03:50:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-26 03:50:14 +0200 |
| commit | 878a7d6ea5ddbc5f813bd45dbb3633e4317ad2a9 (patch) | |
| tree | 57efa9d70c50befa5c4552ae27f57a32e17eec86 /src | |
| parent | 09a7051d2835791adec116b07e05381335a253fc (diff) | |
| parent | 6aa5a5df965db2d6f567fe34a316b5f4e0234c15 (diff) | |
| download | rust-878a7d6ea5ddbc5f813bd45dbb3633e4317ad2a9.tar.gz rust-878a7d6ea5ddbc5f813bd45dbb3633e4317ad2a9.zip | |
Rollup merge of #60134 - GuillaumeGomez:fix-index-page, r=Manishearth
Fix index-page generation Fixes #60096. The minifier was minifying crates name in `searchIndex` key position, which was a bit problematic for multiple reasons. r? @rust-lang/rustdoc
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/Cargo.toml | 2 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 37 | ||||
| -rw-r--r-- | src/test/rustdoc/index-page.rs | 3 |
3 files changed, 15 insertions, 27 deletions
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 4941867d8df..6cedab412df 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -10,6 +10,6 @@ path = "lib.rs" [dependencies] pulldown-cmark = { version = "0.4.1", default-features = false } -minifier = "0.0.29" +minifier = "0.0.30" tempfile = "3" parking_lot = "0.7" diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 0bc06ea8b3b..3e6aeddeae0 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -951,40 +951,15 @@ themePicker.onblur = handleThemeButtonsBlur; key: &str, for_search_index: bool, ) -> io::Result<(Vec<String>, Vec<String>, Vec<String>)> { - use minifier::js; - let mut ret = Vec::new(); let mut krates = Vec::new(); let mut variables = Vec::new(); - let mut krate = krate.to_owned(); - if path.exists() { for line in BufReader::new(File::open(path)?).lines() { let line = line?; if for_search_index && line.starts_with("var R") { variables.push(line.clone()); - // We need to check if the crate name has been put into a variable as well. - let tokens: js::Tokens<'_> = js::simple_minify(&line) - .into_iter() - .filter(js::clean_token) - .collect::<Vec<_>>() - .into(); - let mut pos = 0; - while pos < tokens.len() { - if let Some((var_pos, Some(value_pos))) = - js::get_variable_name_and_value_positions(&tokens, pos) { - if let Some(s) = tokens.0[value_pos].get_string() { - if &s[1..s.len() - 1] == krate { - if let Some(var) = tokens[var_pos].get_other() { - krate = var.to_owned(); - break - } - } - } - } - pos += 1; - } continue; } if !line.starts_with(key) { @@ -1340,10 +1315,20 @@ fn write_minify_replacer<W: Write>( .into(); tokens.apply(|f| { // We add a backline after the newly created variables. - minifier::js::aggregate_strings_into_array_with_separation( + minifier::js::aggregate_strings_into_array_with_separation_filter( f, "R", Token::Char(ReservedChar::Backline), + // This closure prevents crates' names from being aggregated. + // + // The point here is to check if the string is preceded by '[' and + // "searchIndex". If so, it means this is a crate name and that it + // shouldn't be aggregated. + |tokens, pos| { + pos < 2 || + !tokens[pos - 1].is_char(ReservedChar::OpenBracket) || + tokens[pos - 2].get_other() != Some("searchIndex") + } ) }) .to_string() diff --git a/src/test/rustdoc/index-page.rs b/src/test/rustdoc/index-page.rs index 6998e735297..f0476f083b8 100644 --- a/src/test/rustdoc/index-page.rs +++ b/src/test/rustdoc/index-page.rs @@ -1,3 +1,5 @@ +// aux-build:all-item-types.rs +// build-aux-docs // compile-flags: -Z unstable-options --enable-index-page #![crate_name = "foo"] @@ -5,4 +7,5 @@ // @has foo/../index.html // @has - '//span[@class="in-band"]' 'List of all crates' // @has - '//ul[@class="mod"]//a[@href="foo/index.html"]' 'foo' +// @has - '//ul[@class="mod"]//a[@href="all_item_types/index.html"]' 'all_item_types' pub struct Foo; |
