forked from profezzorn/ProffieOSDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.html
51 lines (46 loc) · 1.45 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
---
title: Search page
meta: true
layout: default
---
<script src="/js/elasticlunr.min.js"></script>
<div style=display:none>
{% for p in site.pages %}
{% if p.title and p.url != "/" and p.url != "/all_pages.html" and p.url != "/POD.html" and p.url != "/search.html" %}
<searchdata url="{{ p.url | escape }}" title="{{ p.title | escape }}">
{{ p.content | escape}}
</searchdata>
{% endif %}
{% endfor %}
</div>
<div id=results></div>
<script>
var index = elasticlunr(function () {
this.addField('title');
this.addField('body');
this.setRef('id');
});
var tags = document.getElementsByTagName("searchdata");
for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
var id = tag.attributes.url.value;
var title = unescape(tag.attributes.title.value);
var body = unescape(tag.innerHTML);
console.log("id = " + id + " title = " + title);
// console.log("body = " + body);
index.addDoc({ "id": id, "title": title, "body": body });
}
var searchstr = decodeURIComponent( window.location.search.substr(3).replace(/\+/g, '%20') )
var results = index.search(searchstr);
var ret = "";
if (results.length > 0) {
ret += "<ul>\n";
for (var i = 0; i < results.length; i++) {
ret += "<li><a href='"+results[i].ref + "'>" + results[i].doc.title + "</a></li>\n";
}
ret += "</ul>\n";
} else {
ret += "No results found, sorry.";
}
document.getElementById("results").innerHTML = ret;
</script>