Skip to content

Commit f34805a

Browse files
committed
Add the library search box on the 404 page
It actually has a link to search already, but it would be better to have the search "box" as like index.md to be consistent. <style> can be shared with index.md, but these pages currently use https://doc.rust-lang.org/rust.css directly. Fixes rust-lang#14572.
1 parent c3a1a0d commit f34805a

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

src/doc/not_found.md

+32-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
#TOC { display: none; }
66
.header-section-number { display: none; }
77
li {list-style-type: none; }
8+
.search-input {
9+
width: calc(100% - 200px);
10+
}
11+
.search-but {
12+
cursor: pointer;
13+
}
14+
.search-but, .search-input {
15+
padding: 4px;
16+
border: 1px solid #ccc;
17+
border-radius: 3px;
18+
outline: none;
19+
font-size: 0.7em;
20+
background-color: #fff;
21+
}
22+
.search-but:hover, .search-input:focus {
23+
border-color: #55a9ff;
24+
}
825
</style>
926

1027
Looks like you've taken a wrong turn.
@@ -13,11 +30,20 @@ Some things that might be helpful to you though:
1330

1431
# Search
1532

16-
<form action="https://duckduckgo.com/">
17-
<input type="text" id="site-search" name="q" size="80"></input>
18-
<input type="submit" value="Search DuckDuckGo"></form>
19-
20-
Rust doc search: <span id="core-search"></span>
33+
<div>
34+
<form action="std/index.html" method="get">
35+
<input id="std-search" class="search-input" type="search" name="search"
36+
placeholder="Search through the standard library"/>
37+
<button class="search-but">Search Standard Library</button>
38+
</form>
39+
</div>
40+
41+
<div>
42+
<form action="https://duckduckgo.com/">
43+
<input id="site-search" class="search-input" type="search" name="q"></input>
44+
<input type="submit" value="Search DuckDuckGo" class="search-but">
45+
</form>
46+
</div>
2147

2248
# Reference
2349

@@ -53,16 +79,7 @@ function populate_site_search() {
5379

5480
function populate_rust_search() {
5581
var op = get_url_fragments();
56-
var lt = op.pop();
57-
58-
// #18540, use a single token
59-
60-
var a = document.createElement("a");
61-
a.href = "https://doc.rust-lang.org/core/?search=" + encodeURIComponent(lt);
62-
a.textContent = lt;
63-
var search = document.getElementById('core-search');
64-
search.innerHTML = "";
65-
search.appendChild(a);
82+
document.getElementById('std-search').value = op.join(' ');
6683
}
6784
populate_site_search();
6885
populate_rust_search();

0 commit comments

Comments
 (0)