2022-01-04 20:42:55 +08:00
---
layout: default
title: 搜索
---
< h1 > 搜索</ h1 >
2025-05-15 08:51:18 +00:00
< form action = "https://www.google.com/search" >
2025-05-15 09:31:09 +00:00
< input type = "hidden" name = "as_sitesearch" value = "mabbs.github.io" />
2025-06-17 03:56:14 +00:00
< p >< center >< input name = "q" type = "text" id = "search-input" placeholder = "Search blog posts.." /> < img src = "/images/loading.svg" alt = "Loading..." id = "search-loading" style = "width:22px;vertical-align: bottom" /> < input type = "submit" value = "谷歌搜索" style = "margin-left: 5px;" /></ center ></ p >
2025-05-15 08:51:18 +00:00
</ form >
2022-01-04 20:42:55 +08:00
< ul id = "results-container" ></ ul >
< script >
2025-06-02 05:26:23 +00:00
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 ( '' );
}
var mykeyword = decodeURI ( getQueryVariable ( "keyword" ));
var sbox = document . getElementById ( 'search-input' );
2025-04-03 14:38:40 +00:00
if ( mykeyword ) {
sbox . value = mykeyword ;
2022-01-04 20:42:55 +08:00
}
2025-06-02 05:26:23 +00:00
</ script >
< script src = "/assets/js/simple-jekyll-search.min.js" ></ script >
< script >
2026-05-21 07:38:17 +00:00
function _doSearch ( json ) {
2022-01-04 20:42:55 +08:00
var sjs = SimpleJekyllSearch ({
searchInput : sbox ,
resultsContainer : document . getElementById ( 'results-container' ),
json : json ,
2025-05-15 08:51:18 +00:00
searchResultTemplate : '<li><p>{date} - <a href="{url}?kw={query}">{title}</a></p></li>' ,
2022-01-04 20:42:55 +08:00
limit : 20
});
sjs . search ( mykeyword );
document . getElementById ( 'search-loading' ). style . display = "none" ;
2026-05-21 07:38:17 +00:00
}
getSearchJSON ( function ( json ) {
if ( typeof SimpleJekyllSearch !== 'undefined' ) {
_doSearch ( json );
} else {
// PJAX 场景:外部脚本通过 pjax 库异步加载,需要等待加载完成
var _poll = 0 ;
var _waitSJS = setInterval ( function () {
if ( typeof SimpleJekyllSearch !== 'undefined' ) {
clearInterval ( _waitSJS );
_doSearch ( json );
} else if ( ++ _poll > 100 ) {
clearInterval ( _waitSJS );
document . getElementById ( 'search-loading' ). style . display = "none" ;
}
}, 50 );
}
2022-01-04 20:42:55 +08:00
});
2025-06-17 03:56:14 +00:00
</ script >