-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
search.html
41 lines (39 loc) · 1.33 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
---
layout: default
title: 搜索
---
<h1>搜索</h1>
<!-- HTML elements for search -->
<p>Keyword: <input type="text" id="search-input" placeholder="Search blog posts.."> <img src="/images/loading.svg" id="search-loading" style="width:22px;vertical-align: bottom"></p>
<ul id="results-container"></ul>
<!-- or without installing anything -->
<script src="https://unpkg.com/simple-jekyll-search@latest/dest/simple-jekyll-search.min.js"></script>
<script>
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
var mykeyword = decodeURI(getQueryVariable("keyword"));
var sbox = document.getElementById('search-input');
var status = false;
if(mykeyword != null && mykeyword.toString().length>1){
sbox.value = mykeyword;
}
getSearchJSON(function(json){
var sjs = SimpleJekyllSearch({
searchInput: sbox,
resultsContainer: document.getElementById('results-container'),
json: json,
searchResultTemplate: '<p><li>{date} - <a href="{url}">{title}</a></li></p>',
limit: 20
});
sjs.search(mykeyword);
document.getElementById('search-loading').style.display = "none";
});
</script>