From 68e3c49cdf1470ce78cd96a08877e09dabacdf93 Mon Sep 17 00:00:00 2001 From: Jean-Luc Thumm Date: Mon, 31 May 2021 19:20:41 -0700 Subject: [PATCH 1/2] Add go_to_first boolean query param to immeidately jump to the first search result --- src/librustdoc/html/static/search.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js index 67be7b9915502..0aebb0e9d6588 100644 --- a/src/librustdoc/html/static/search.js +++ b/src/librustdoc/html/static/search.js @@ -1058,14 +1058,14 @@ window.initSearch = function(rawSearchIndex) { return ""; } - function showResults(results) { + function showResults(results, go_to_first) { var search = searchState.outputElement(); - if (results.others.length === 1 + if (go_to_first || (results.others.length === 1 && getSettingValue("go-to-only-result") === "true" // By default, the search DOM element is "empty" (meaning it has no children not // text content). Once a search has been run, it won't be empty, even if you press // ESC or empty the search input (which also "cancels" the search). - && (!search.firstChild || search.firstChild.innerText !== searchState.loadingText)) + && (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))) { var elem = document.createElement("a"); elem.href = results.others[0].href; @@ -1242,7 +1242,7 @@ window.initSearch = function(rawSearchIndex) { } var filterCrates = getFilterCrates(); - showResults(execSearch(query, index, filterCrates)); + showResults(execSearch(query, index, filterCrates), params.go_to_first); } function buildIndex(rawSearchIndex) { From 6c5c0a58535e050501afe66204f477c013468e54 Mon Sep 17 00:00:00 2001 From: Jean-Luc Thumm Date: Tue, 22 Jun 2021 15:40:37 -0700 Subject: [PATCH 2/2] Add Website features page to rustdoc book --- src/doc/rustdoc/src/SUMMARY.md | 1 + src/doc/rustdoc/src/website-features.md | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/doc/rustdoc/src/website-features.md diff --git a/src/doc/rustdoc/src/SUMMARY.md b/src/doc/rustdoc/src/SUMMARY.md index ae94527e2b4ca..3fa91bb51f02f 100644 --- a/src/doc/rustdoc/src/SUMMARY.md +++ b/src/doc/rustdoc/src/SUMMARY.md @@ -10,5 +10,6 @@ - [Lints](lints.md) - [Advanced features](advanced-features.md) - [Unstable features](unstable-features.md) +- [Website features](website-features.md) - [Passes](passes.md) - [References](references.md) diff --git a/src/doc/rustdoc/src/website-features.md b/src/doc/rustdoc/src/website-features.md new file mode 100644 index 0000000000000..5fade4e84a992 --- /dev/null +++ b/src/doc/rustdoc/src/website-features.md @@ -0,0 +1,25 @@ +# Website features + +These features are about using the website generated by `rustdoc`. + +## Custom search engines + +If you find yourself often referencing online Rust docs you might enjoy using a custom search +engine. This allows you to use the navigation bar directly to search a `rustdoc` website. +Most browsers support this feature by letting you define a URL template containing `%s` +which will be substituted for the search term. As an example, for the standard library you could use +this template: + +```text +https://doc.rust-lang.org/stable/std/?search=%s +``` + +Note that this will take you to a results page listing all matches. If you want to navigate to the first +result right away (which is often the best match) use the following instead: + +```text +https://doc.rust-lang.org/stable/std/?search=%s&go_to_first=true +``` + +This URL adds the `go_to_first=true` query parameter which can be appended to any `rustdoc` search URL +to automatically go to the first result.