blob: b022c8d314e73bad9dad21843a77bb50ba296e24 (
plain)
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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Search — {{ site.title }}</title>
<link rel="stylesheet" href="{{ site.url }}style.css">
</head>
<body>
<header>
<h1><a href="/">{{ site.title }}</a></h1>
<nav><a href="/">home</a></nav>
</header>
<main>
<input type="search" id="q" placeholder="search posts..." autofocus>
<ul id="results" class="post-list"></ul>
</main>
<footer><p>{{ site.author }}</p></footer>
<script>
var idx = [];
fetch("/search.json").then(function(r){return r.json()}).then(function(d){idx=d});
document.getElementById("q").addEventListener("input", function(){
var q = this.value.toLowerCase().trim();
var html = "";
if (q.length < 2) { document.getElementById("results").innerHTML = ""; return; }
for (var i = 0; i < idx.length; i++) {
var p = idx[i];
if (p.title.toLowerCase().indexOf(q) >= 0 || p.text.toLowerCase().indexOf(q) >= 0) {
html += '<li><h2><a href="/' + p.slug + '/">' + p.title + '</a></h2><span class="meta">' + p.date + '</span></li>';
}
}
document.getElementById("results").innerHTML = html || "<li class='none'>no results</li>";
});
</script>
</body>
</html>
|