2022-01-04 20:42:55 +08:00
---
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 ;
}
2024-09-29 15:20:22 +00:00
getSearchJSON ( function ( json ) {
2022-01-04 20:42:55 +08:00
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 >