-
Notifications
You must be signed in to change notification settings - Fork 16
/
search.html
47 lines (40 loc) · 1.66 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
---
layout: home
title: "Search"
---
<script src="{{ site.baseurl }}/js/jquery-2.2.4.min.js"></script>
<script src="{{ site.baseurl }}/js/search.js"></script>
<form class="search-form" action="{{ site.baseurl }}/search.html" method="get">
<input id="search-input" class="search-input" type="text" name="search" placeholder="Search..."></input><input class="search-submit" type="submit" value="Search"></input>
</form>
<script type="text/javascript">
var search = getGetVariable("search");
if (search != null && search != "") {
document.title = document.title.replace("{{page.title}} | ", "{{page.title}} for \""+search+"\" | ");
document.getElementById("search-input").value = htmlDecode(search);
var regex = new RegExp(search, 'igm');
$.getJSON( "search.json", function( data ) {
var items = [];
for (var i = 0; i < data.length; i++) {
if (regex.test(data[i].title) || regex.test(data[i].content) ||
regex.test(data[i].tags) || regex.test(data[i].category)) {
items.push("<div class=\"search-item\">");
if (data[i].section != "") {
items.push(data[i].section + "> ");
}
items.push("<a href=\""+ data[i].url +"\">" + data[i].title + "</a>");
items.push("<div class=\"search-excerpt\">" + getExcerpt(unescape(htmlDecode(data[i].content)), regex, 320) + "</div></div>");
}
}
if (items.length < 1) {
items.push("<div class=\"search-item\">No results</div>");
}
$( "<div/>", {
"class": "search-results",
html: items.join("")
}).appendTo(".results-container");
});
} else {
}
</script>
<div class="results-container"></div>