-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_template.hbs
52 lines (40 loc) · 1.28 KB
/
index_template.hbs
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
<html>
<head>
<meta charset="utf-8">
<title>Random thoughts</title>
<link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura-dark.css" type="text/css">
</head>
<body>
<h1>Just some random junk...</h1>
{{#each articles as |article|}}
<h5><a href="{{article.filename}}.html">{{article.title}}</a> <small>{{article.modified_at}}</small></h5>
{{/each}}
<br>
<div>
<label for="search_input">Search</label>
<input type="search" id="search_input" />
<div id="search_results"></div>
</div>
<script>
const search = document.getElementById('search_input');
const search_results = document.getElementById('search_results');
var search_data = [];
search.onfocus = async function (ev) {
const data = await fetch("search_data.json");
search_data = await data.json();
}
search.addEventListener('input' , () => searchArticles(search.value));
function searchArticles(term) {
if (term.length == 0) {
search_results.innerHTML = "";
return;
}
const matches = search_data.filter(entry => entry.body.includes(term));
const html = matches.map(match => `
<h5><a href="${match.link}">${match.title}</a></h5>
`).join('');
search_results.innerHTML = html;
}
</script>
</body>
</html>