about summary refs log tree commit diff
path: root/src/librustdoc/html/layout.rs
AgeCommit message (Collapse)AuthorLines
2021-06-20Use Tera templates for rustdoc.Jacob Hoffman-Andrews-174/+40
Replaces a format!() call in layout::render with a template expansion. Introduces a `templates` field in SharedContext so parts of rustdoc can share pre-rendered templates. This currently builds in a copy of the single template available, like with static files. However, future work can make this live-loadable with a perma-unstable flag, to make rustdoc developers' work easier.
2021-06-05Add missing backslash in HTML layout stringGuillaume Gomez-1/+1
2021-06-05Escape <meta> content attribute valueGuillaume Gomez-1/+1
2021-06-05Rollup merge of #85503 - liigo:tooltips, r=GuillaumeGomezGuillaume Gomez-3/+3
rustdoc: add tooltips to some buttons
2021-06-03Auto merge of #84834 - GuillaumeGomez:sidebar-unification, r=jshabors-1/+1
Sidebar unification This PR does a few things: * Put crates list at all levels (before, it was only on the "top" items) * Fix bug in module sidebar: the list of items was from the parent module. The other changes (on bootstrap mostly) were to allow to generate multiple crates in a same folder so that we can ensure that clicking on the crates in the sidebar works as expected. I added a rustdoc-gui test to ensure everything is where it should be. r? `@jyn514`
2021-06-01Add missing <title> in redirection page <head>Guillaume Gomez-0/+1
2021-05-31* Put crates list at all levelsGuillaume Gomez-1/+1
* Fix bug in module sidebar: the list of items was from the parent module
2021-05-20rustdoc: add tooltips to some buttonsLiigo Zhuang-3/+3
2021-05-11Move global click handlers to per-element ones.Jacob Hoffman-Andrews-1/+1
In rustdoc's main.js, we had an onclick handler for the whole document that would dispatch to handlers for various elements. This change attaches the handlers to the elements that trigger them, instead. This simplfies the code and avoids reimplementing the browser's bubbling functionality. As part of this change, change from a class to an id for help button. Move the handlers and associated code for highlighting source lines into source-script.js (and factor out a shared regex).
2021-05-10Use an SVG image for clipboard instead of unicode characterGuillaume Gomez-1/+7
2021-04-20Rollup merge of #84340 - notriddle:patch-4, r=GuillaumeGomezDylan DPC-1/+1
rustdoc: Show nag box on IE11 Rustdoc doesn't work on IE11. It's been broken for months, it isn't supported by the [tiered browser support list], it's even more severely broken on other Rust websites, and IE11 doesn't support the `<details>` tag that we want to use. In the interest of honesty, let's give an actual error message for anyone on IE11. [tiered browser support list]: https://github.com/rust-lang/rfcs/blob/master/text/1985-tiered-browser-support.md
2021-04-19rustdoc: Show nag box on IE10Michael Howell-1/+1
Rustdoc doesn't work on IE11. It's been broken for months, it isn't supported by the [tiered browser support list], it's even more severely broken on other Rust websites, and IE11 doesn't support the `<details>` tag that we want to use. In the interest of honesty, let's give an actual error message for anyone on IE11. [tiered browser support list]: https://github.com/rust-lang/rfcs/blob/master/text/1985-tiered-browser-support.md
2021-04-19Remove unused footer sectionGuillaume Gomez-1/+0
2021-04-14Change root_path to static_root_pathJacob Hoffman-Andrews-1/+1
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2021-04-13Split search.js from search-index.js.Jacob Hoffman-Andrews-1/+2
2021-03-23Rollup merge of #82732 - GuillaumeGomez:remove-theme-file, r=Nemo157Yuki Okushi-1/+0
Remove theme.js file Fixes #82616. The first commit moves the `theme.js` file into `main.js`, which requires to also run a small `.replace` on the `main.js` content. The second commit is just a small cleanup to centralize DOM ids. Since it removes a file from rustdoc output: cc `@rust-lang/docs-rs` cc `@jsha` r? `@jyn514`
2021-03-13crates.js should use root_path and not static_root_pathGuillaume Gomez-1/+1
2021-03-05Remove theme.js file creation and move its code inside main.jsGuillaume Gomez-1/+0
2021-03-04Rollup merge of #82315 - jsha:font-display-swap, r=GuillaumeGomezYuki Okushi-2/+2
Improve page load performance in rustdoc Add an explicit height to icons (which already had an explicit width) to allow browsers to lay out the page more accurately before the icons have been loaded. https://web.dev/optimize-cls/. Add min-width: 115px to the crate search dropdown. When the HTML first loads, this dropdown includes only the text "All crates." Later, JS loads the items underneath it, some of which are wider. That causes the dropdown to get wider, causing a distracting reflow. This sets a min-width based on the size that the dropdown eventually becomes based on the crates on doc.rust-lang.org, reducing page movement during load. Add font-display: swap. Per https://web.dev/font-display/, this prevents "flash of invisible text" during load by using a system font until the custom font is available. I've noticed this flash of invisible text occasionally when reading Rust docs. Note that users without cached fonts will see text, and then see it reflow. For `docs.rust-lang.org`, [setting caching headers will help a lot](https://github.com/rust-lang/simpleinfra/issues/62). Generated output at https://jacob.hoffman-andrews.com/rust/flow-improvements/std/string/struct.String.html.
2021-03-04Rollup merge of #82310 - jsha:rustdoc-search-onfocus, r=GuillaumeGomezYuki Okushi-2/+3
Load rustdoc's JS search index on-demand. Instead of being loaded on every page, the JS search index is now loaded when either (a) there is a `?search=` param, or (b) the search input is focused. This saves both CPU and bandwidth. As of Feb 2021, https://doc.rust-lang.org/search-index1.50.0.js is 273,838 bytes gzipped or 2,544,939 bytes uncompressed. Evaluating it takes 445 ms of CPU time in Chrome 88 on a i7-10710U CPU (out of a total ~2,100 ms page reload). Tested on Firefox and Chrome. New: https://jacob.hoffman-andrews.com/rust/search-on-demand/std/primitive.slice.html https://jacob.hoffman-andrews.com/rust/search-on-demand/std/primitive.slice.html?search=fn Old: https://jacob.hoffman-andrews.com/rust/search-on-load/std/primitive.slice.html https://jacob.hoffman-andrews.com/rust/search-on-load/std/primitive.slice.html?search=fn
2021-03-02Improve page load performance in rustdoc.Jacob Hoffman-Andrews-2/+2
Add font-display: swap. Per https://web.dev/font-display/, this prevents "flash of invisible text" during load by using a system font until the custom font is available. I've noticed this flash of invisible text occasionally when reading Rust docs. Add an explicit height to icons (which already had an explicit width) to allow browsers to lay out the page more accurately before the icons have been loaded. https://web.dev/optimize-cls/. Add min-width: 115px to the crate search dropdown. When the HTML first loads, this dropdown includes only the text "All crates." Later, JS loads the items underneath it, some of which are wider. That causes the dropdown to get wider, causing a distracting reflow. This sets a min-width based on the size that the dropdown eventually becomes based on the crates on doc.rust-lang.org, reducing page movement during load.
2021-03-02Load rustdoc's JS search index on-demand.Jacob Hoffman-Andrews-2/+3
Instead of being loaded on every page, the JS search index is now loaded when either (a) there is a `?search=` param, or (b) the search input is focused. This saves both CPU and bandwidth. As of Feb 2021, https://doc.rust-lang.org/search-index1.50.0.js is 273,838 bytes gzipped or 2,544,939 bytes uncompressed. Evaluating it takes 445 ms of CPU time in Chrome 88 on a i7-10710U CPU (out of a total ~2,100 ms page reload). Generate separate JS file with crate names. This is much smaller than the full search index, and is used in the "hot path" to draw the page. In particular it's used to crate the dropdown for the search bar, and to append a list of crates to the sidebar (on some pages). Skip early search that can bypass 500ms timeout. This was occurring when someone had typed some text during the load of search-index.js. Their query was usually not ready to execute, and the search itself is fairly expensive, delaying the overall load, which delayed the input / keyup events, which delayed eventually executing the query.
2021-02-27Add ARIA role to sidebar toggle in RustdocVincent Ambo-1/+1
This indicates that the div is an interactive element, and makes the sidebar toggle "clickable" in assistive technologies. Fixes #82582
2021-01-30rustdoc tweakingbors-15/+11
* Reuse memory * simplify `next_def_id`, avoid multiple hashing and unnecessary lookups * remove `all_fake_def_ids`, use the global map instead (probably not a good step toward parallelization, though...) * convert `add_deref_target` to iterative implementation * use `ArrayVec` where we know the max number of elements * minor touchups here and there * avoid building temporary vectors that get appended to other vectors At most places I may or may not be doing the compiler's job is this PR.
2021-01-21Fix rustc::internal lints on rustdocJoshua Nelson-2/+3
2021-01-18Remove inline script tagsGuillaume Gomez-4/+1
2020-12-13Fixes submit event of the search inputGuillaume Gomez-1/+1
In HTML, when a button follows an input, if the enter keep is pressed on the input, instead of sending the submit event to the input, it'll create a click event on the button following it, which in this case made the help popup show up whenever "enter" was pressed.
2020-12-10Make search results tab and help button focusable with keyboardGuillaume Gomez-1/+1
2020-11-15Make all rustdoc functions and structs crate-privateJoshua Nelson-20/+20
This gives warnings about dead code.
2020-10-30Add aria roles for theme picker menuMichael Howell-2/+2
2020-10-28rustdoc: Fix some nitsIan Jackson-1/+1
* Remove a needless comma in the Rust code * Replace double spaces after full stops with single spaces Requested-by: @GuillaumeGomez Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-10-28rustdoc: Provide a general --default-setting SETTING[=VALUE] optionIan Jackson-1/+1
We just plumb through what the user tells us. This is flagged as unstable, mostly because I don't understand the compatibility rules that rustdoc obeys for local storage data, and how error handling of invalid data works. We collect() the needed HashMap from Vec of Vecs of (key, value) pairs, so that there is a nice place to add new more-specific options. It would have been possible to use Extend::extend but doing it this way ensures that all the used inputs are (and will stay) right next to each other. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-10-28rustdoc: Provide a way to set the default settings from Rust codeIan Jackson-0/+8
rustdoc has various user-configurable preferences. These are recorded in web Local Storage (where available). But we want to provide a way to configure the default default, including for when web storage is not available. getSettingValue is the function responsible for looking up these settings. Here we make it fall back some in-DOM data, which ultimately comes from RenderOptions.default_settings. Using HTML data atrtributes is fairly convenient here, dsspite the need to transform between snake and kebab case to avoid the DOM converting kebab case to camel case (!) We cache the element and dataset lookup in a global variable, to ensure that getSettingValue remains fast. The DOM representation has to be in an element which precedes the inclusion of storage.js. That means it has to be in the <head> and we should not use an empty <div> as the container (although most browsers will accept that). An empty <script> element provides a convenient and harmless container object. <meta> would be another possibility but runs a greater risk of having unwanted behaviours on weird browsers. We trust the RenderOptions not to contain unhelpful setting names, which don't fit nicely into an HTML attribute. It's awkward to quote dataset keys. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-09-23Use theme-adaptive SVG favicon from other Rust sitesJarek Samic-1/+3
2020-08-31Fix strings indentGuillaume Gomez-2/+2
2020-08-11Rollup merge of #75366 - GuillaumeGomez:help-button, r=jyn514Dylan DPC-0/+1
Add help button Part of #75197. Here is a screenshot of the result: ![Screenshot from 2020-08-10 16-53-20](https://user-images.githubusercontent.com/3050060/89796547-14112a00-db2a-11ea-9f25-57b30ab68f9b.png) r? @jyn514
2020-08-10Add help buttonGuillaume Gomez-0/+1
2020-08-07Only add a border for the rust logoGuillaume Gomez-1/+1
2020-07-12Clean up handling of style files in rustdocJarek Samic-11/+14
Disable all themes other than `light.css` to prevent rule conflicts
2020-05-07Merge aliases and search-indexGuillaume Gomez-1/+0
2019-12-22Format the worldMark Rousskov-68/+88
2019-11-20Rollup merge of #66298 - Ppjet6:disable-search-field, r=GuillaumeGomezMazdak Farrokhzad-1/+2
rustdoc: fixes #64305: disable search field instead of hidding it The result seems to be ok but I wasn't entirely sure how to get there. I tried to stay generic a bit but maybe it's not required at all. @GuillaumeGomez Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2019-11-20rustdoc: fixes #64305: disable search field instead of hidding itMaxime “pep” Buquet-1/+2
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2019-11-18Apply review commentsGuillaume Gomez-4/+6
2019-10-27reduce size of generated HTML files by moving the popup helper code to the JSGuillaume Gomez-55/+0
2019-10-26Add more information on searchGuillaume Gomez-0/+8
2019-09-13Replace SlashChecker with ensure_trailing_slashMark Rousskov-2/+2
2019-09-07layout::render takes Print instead of fmt::DisplayMark Rousskov-4/+3
2019-09-07Implement Print for FnOnce(&mut Buffer)Mark Rousskov-1/+1
This means that callers can pass in a closure like `|buf| some_function(..., &mut buf)` and pass in arbitrary arguments to that function without complicating the trait definition. We also keep the impl for str and String, since it's useful to be able to just pass in "" or format!("{}"...) results in some cases. This changes Print's definition to take self, instead of &self, because otherwise FnOnce cannot be called directly. We could instead take FnMut or even Fn, but that seems like it'd merely complicate matters -- most of the time, the FnOnce does not constrain us at all anyway. If it does, a custom Print impl for &'_ SomeStruct is not all that painful.
2019-09-07Move sidebar to Buffer-printingMark Rousskov-2/+3