-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.json
33 lines (30 loc) · 973 Bytes
/
index.json
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
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4 && httpRequest.status === 200) {
const index = JSON.parse(httpRequest.responseText);
// XMLHttpRequest boilerplate from above
// ...
const index = JSON.parse(httpRequest.responseText);
const keys = ["title", "permalink", "tags", "contents"];
const pattern = new RegExp(query); // See below for how we get the query
const results = index.filter(item => {
for (var i = 0; i < keys.length; i++) {
const key = keys[i];
if (!item[key]) {
continue;
}
if (key === "tags") {
if (item[key].some(tag => pattern.test(tag.toLowerCase()))) {
return true;
}
} else if (pattern.test(item[key].toLowerCase())) {
return true;
}
}
return false;
});
// ...
}
};
httpRequest.open("GET", "/index.json");
httpRequest.send();