Skip to content

Commit eca7ab5

Browse files
cleaned up ids, added direct rust doc search
Search functionality uses both duckduckgo for site wide doc search and the rust specific documentation search @ http://doc.rust-lang.org/core/?search=unwrap_or_else
1 parent f878a88 commit eca7ab5

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/doc/not_found.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Some things that might be helpful to you though:
1313

1414
## Search
1515
* <form action="https://duckduckgo.com/">
16-
<input type="text" id="code.search" name="q" size="80"></input>
16+
<input type="text" id="site-search" name="q" size="80"></input>
1717
<input type="submit" value="Search DuckDuckGo">
1818
</form>
19+
* Rust doc search: <span id="core-search"></span>
1920

2021
## Reference
2122
* [The Rust official site](http://rust-lang.org)
@@ -25,19 +26,38 @@ Some things that might be helpful to you though:
2526
* [The standard library](http://doc.rust-lang.org/std/)
2627

2728
<script>
28-
function populate_search_box() {
29-
29+
function get_url_fragments() {
3030
var last = document.URL.split("/").pop();
3131
var tokens = last.split(".");
3232
var op = [];
3333
for (var i=0; i < tokens.length; i++) {
34-
if (tokens[i].indexOf("#") == -1)
35-
op.push(tokens[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+
}
3640
}
41+
return op;
42+
}
3743

38-
var search = document.getElementById('code.search');
44+
function populate_site_search() {
45+
var op = get_url_fragments();
46+
47+
var search = document.getElementById('site-search');
3948
search.value = op.join(' ') + " site:doc.rust-lang.org";
4049
}
41-
populate_search_box();
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();
4262
</script>
4363

0 commit comments

Comments
 (0)