Skip to content

Commit bb70ee5

Browse files
committed
auto merge of #18528 : seanjensengrey/rust/doc-18498, r=brson
This addresses #18498 by adding a prepopulated search box to do site search on `doc.rust-lang.org` using duckduckgo AND generating a search url against the rust documentation using the internal search facilities. * https://duckduckgo.com/?q=type+Option+unwrap_or_else+site%3Adoc.rust-lang.org * http://doc.rust-lang.org/core/?search=unwrap_or_else
2 parents 1b2ad78 + eca7ab5 commit bb70ee5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/doc/not_found.md

+44
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,53 @@ Looks like you've taken a wrong turn.
1111

1212
Some things that might be helpful to you though:
1313

14+
## Search
15+
* <form action="https://duckduckgo.com/">
16+
<input type="text" id="site-search" name="q" size="80"></input>
17+
<input type="submit" value="Search DuckDuckGo">
18+
</form>
19+
* Rust doc search: <span id="core-search"></span>
20+
1421
## Reference
1522
* [The Rust official site](http://rust-lang.org)
1623
* [The Rust reference](http://doc.rust-lang.org/reference.html) (* [PDF](http://doc.rust-lang.org/reference.pdf))
1724

1825
## Docs
1926
* [The standard library](http://doc.rust-lang.org/std/)
27+
28+
<script>
29+
function get_url_fragments() {
30+
var last = document.URL.split("/").pop();
31+
var tokens = last.split(".");
32+
var op = [];
33+
for (var i=0; i < tokens.length; i++) {
34+
var t = tokens[i];
35+
if (t == 'html' || t.indexOf("#") != -1) {
36+
// no html or anchors
37+
} else {
38+
op.push(t);
39+
}
40+
}
41+
return op;
42+
}
43+
44+
function populate_site_search() {
45+
var op = get_url_fragments();
46+
47+
var search = document.getElementById('site-search');
48+
search.value = op.join(' ') + " site:doc.rust-lang.org";
49+
}
50+
51+
function populate_rust_search() {
52+
var op = get_url_fragments();
53+
var lt = op.pop();
54+
55+
// #18540, use a single token
56+
57+
var search = document.getElementById('core-search');
58+
search.innerHTML = "<a href=\"http://doc.rust-lang.org/core/?search=" + lt + "\">" + lt + "</a>";
59+
}
60+
populate_site_search();
61+
populate_rust_search();
62+
</script>
63+

0 commit comments

Comments
 (0)