-
Notifications
You must be signed in to change notification settings - Fork 4
/
search.html
56 lines (50 loc) · 2.25 KB
/
search.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
layout: page
title: Search
---
<div id="lunrsearchresults">
<div id="resultsmodal" tabindex="-1" role="dialog" aria-labelledby="resultsmodal">
<div role="document">
<div id="modtit"></div>
<ul>
</ul>
</div>
</div>
</div>
<script>
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('q');
function lunr_search(term) {
if (term) {
document.getElementById('modtit').innerHTML = "<h5>Search results for '" + term + "'</h5>" + document.getElementById('modtit').innerHTML;
//put results on the screen.
var results = idx.search(term);
if (results.length > 0) {
//console.log(idx.search(term));
//if results
for (var i = 0; i < results.length; i++) {
// more statements
var ref = results[i]['ref'];
var url = documents[ref]['url'];
var title = documents[ref]['title'];
var body = documents[ref]['body'].substring(0, 160) + '...';
document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML + "<li class='lunrsearchresult'><a href='" + url + "'><span class='title'>" + title + "</span><br /><small><span class='body'>" + body + "</span><br /><span class='url'>" + url + "</span></small></a></li>";
}
} else {
document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = "<li class='lunrsearchresult'>Sorry, no results found. Try a different search!</li>";
}
}
else {
document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = "<li class='lunrsearchresult'>Please input a search term.</li>";
}
return false;
}
lunr_search(query);
</script>
<style>
.lunrsearchresult .title {color: #d9230f;}
.lunrsearchresult .url {color: silver;}
.lunrsearchresult a {display: block; color: #777;}
.lunrsearchresult a:hover, .lunrsearchresult a:focus {text-decoration: none;}
.lunrsearchresult a:hover .title {text-decoration: underline;}
</style>