mirror of https://github.com/Mabbs/mabbs.github.io
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							42 lines
						
					
					
						
							1.3 KiB
						
					
					
				
			
		
		
	
	
							42 lines
						
					
					
						
							1.3 KiB
						
					
					
				| ---
 | |
| 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>
 |