Update 2 files

- /assets/js/simple-jekyll-search.min.js
- /search.html
master
mayx 2025-06-17 03:56:14 +00:00
parent 7fbeaffac3
commit c25290e716
2 changed files with 53 additions and 5 deletions

View File

@ -3,4 +3,54 @@
* Copyright 2015-2020, Christian Fei
* Licensed under the MIT License.
*/
!function(){"use strict";var f={compile:function(r){return i.template.replace(i.pattern,function(t,e){var n=i.middleware(e,r[e],i.template);return void 0!==n?n:r[e]||t})},setOptions:function(t){i.pattern=t.pattern||i.pattern,i.template=t.template||i.template,"function"==typeof t.middleware&&(i.middleware=t.middleware)}};const i={pattern:/\{(.*?)\}/g,template:"",middleware:function(){}};var n=function(t,e){var n=e.length,r=t.length;if(n<r)return!1;if(r===n)return t===e;t:for(var i=0,o=0;i<r;i++){for(var u=t.charCodeAt(i);o<n;)if(e.charCodeAt(o++)===u)continue t;return!1}return!0},e=new function(){this.matches=function(t,e){return n(e.toLowerCase(),t.toLowerCase())}},r=new function(){this.matches=function(e,t){return!!e&&(e=e.trim().toLowerCase(),(t=t.trim().toLowerCase()).split(" ").filter(function(t){return 0<=e.indexOf(t)}).length===t.split(" ").length)}},d={put:function(t){if(l(t))return a(t);if(function(t){return Boolean(t)&&"[object Array]"===Object.prototype.toString.call(t)}(t))return function(n){const r=[];s();for(let t=0,e=n.length;t<e;t++)l(n[t])&&r.push(a(n[t]));return r}(t);return undefined},clear:s,search:function(t){return t?function(e,n,r,i){const o=[];for(let t=0;t<e.length&&o.length<i.limit;t++){var u=function(t,e,n,r){for(const i in t)if(!function(n,r){for(let t=0,e=r.length;t<e;t++){var i=r[t];if(new RegExp(i).test(n))return!0}return!1}(t[i],r.exclude)&&n.matches(t[i],e))return t}(e[t],n,r,i);u&&o.push(u)}return o}(u,t,c.searchStrategy,c).sort(c.sort):[]},setOptions:function(t){c=t||{},c.fuzzy=t.fuzzy||!1,c.limit=t.limit||10,c.searchStrategy=t.fuzzy?e:r,c.sort=t.sort||o,c.exclude=t.exclude||[]}};function o(){return 0}const u=[];let c={};function s(){return u.length=0,u}function l(t){return Boolean(t)&&"[object Object]"===Object.prototype.toString.call(t)}function a(t){return u.push(t),u}c.fuzzy=!1,c.limit=10,c.searchStrategy=c.fuzzy?e:r,c.sort=o,c.exclude=[];var p={load:function(t,e){const n=window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");n.open("GET",t,!0),n.onreadystatechange=h(n,e),n.send()}};function h(e,n){return function(){if(4===e.readyState&&200===e.status)try{n(null,JSON.parse(e.responseText))}catch(t){n(t,null)}}}var m=function y(t){if(!(e=t)||!("undefined"!=typeof e.required&&e.required instanceof Array))throw new Error("-- OptionsValidator: required options missing");var e;if(!(this instanceof y))return new y(t);const r=t.required;this.getRequiredOptions=function(){return r},this.validate=function(e){const n=[];return r.forEach(function(t){"undefined"==typeof e[t]&&n.push(t)}),n}},w={merge:function(t,e){const n={};for(const r in t)n[r]=t[r],"undefined"!=typeof e[r]&&(n[r]=e[r]);return n},isJSON:function(t){try{return t instanceof Object&&JSON.parse(JSON.stringify(t))?!0:!1}catch(e){return!1}}};!function(t){let i={searchInput:null,resultsContainer:null,json:[],success:Function.prototype,searchResultTemplate:'<li><a href="{url}" title="{desc}">{title}</a></li>',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[]},n;const e=function(t,e){e?(clearTimeout(n),n=setTimeout(t,e)):t.call()};var r=["searchInput","resultsContainer","json"];const o=m({required:r});function u(t){d.put(t),i.searchInput.addEventListener("input",function(t){-1===[13,16,20,37,38,39,40,91].indexOf(t.which)&&(c(),e(function(){l(t.target.value)},i.debounceTime))})}function c(){i.resultsContainer.innerHTML=""}function s(t){i.resultsContainer.innerHTML+=t}function l(t){var e;(e=t)&&0<e.length&&(c(),function(e,n){var r=e.length;if(0===r)return s(i.noResultsText);for(let t=0;t<r;t++)e[t].query=n,s(f.compile(e[t]))}(d.search(t),t))}function a(t){throw new Error("SimpleJekyllSearch --- "+t)}t.SimpleJekyllSearch=function(t){var n;0<o.validate(t).length&&a("You must specify the following required options: "+r),i=w.merge(i,t),f.setOptions({template:i.searchResultTemplate,middleware:i.templateMiddleware}),d.setOptions({fuzzy:i.fuzzy,limit:i.limit,sort:i.sortMiddleware,exclude:i.exclude}),w.isJSON(i.json)?u(i.json):(n=i.json,p.load(n,function(t,e){t&&a("failed to get JSON ("+n+")"),u(e)}));t={search:l};return"function"==typeof i.success&&i.success.call(t),t}}(window)}();
String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")}),Array.prototype.forEach||(Array.prototype.forEach=function(t,e){var r,n
if(null==this)throw new TypeError(" this is null or not defined")
var i=Object(this),o=i.length>>>0
if("function"!=typeof t)throw new TypeError(t+" is not a function")
for(arguments.length>1&&(r=e),n=0;o>n;){var u
n in i&&(u=i[n],t.call(r,u,n,i)),n++}}),Array.prototype.filter||(Array.prototype.filter=function(t,e){if("Function"!=typeof t&&"function"!=typeof t||!this)throw new TypeError
var r=this.length>>>0,n=Array(r),i=this,o=0,u=-1
if(void 0===e)for(;++u!==r;)u in this&&t(i[u],u,i)&&(n[o++]=i[u])
else for(;++u!==r;)u in this&&t.call(e,i[u],u,i)&&(n[o++]=i[u])
return n.length=o,n}),Array.prototype.indexOf||(Array.prototype.indexOf=function(t,e){var r
if(null==this)throw new TypeError('"this" is null or not defined')
var n=Object(this),i=n.length>>>0
if(0===i)return-1
var o=+e||0
if(Math.abs(o)===1/0&&(o=0),o>=i)return-1
for(r=Math.max(o>=0?o:i-Math.abs(o),0);i>r;){if(r in n&&n[r]===t)return r
r++}return-1}),Object.prototype.toString||(Object.prototype.toString=function(){return"[object "+(this===window?"Window":this===document?"Document":"Object")+"]"}),function(){function t(t){j.pattern=t.pattern||j.pattern,j.template=t.template||j.template,"function"==typeof t.middleware&&(j.middleware=t.middleware)}function e(t){return j.template.replace(j.pattern,function(e,r){var n=j.middleware(r,t[r],j.template)
return void 0!==n?n:t[r]||e})}function r(t,e){var r=e.length,n=t.length
if(n>r)return!1
if(n===r)return t===e
t:for(var i=0,o=0;n>i;i++){for(var u=t.charCodeAt(i);r>o;)if(e.charCodeAt(o++)===u)continue t
return!1}return!0}function n(){this.matches=function(t,e){return T(e.toLowerCase(),t.toLowerCase())}}function i(){this.matches=function(t,e){if(!t)return!1
t=t.trim().toLowerCase(),e=e.trim().toLowerCase()
for(var r=e.split(" "),n=!0,i=0;i<r.length;i++)if(t.indexOf(r[i])<0){n=!1
break}return n}}function o(){return 0}function u(t){return c(t)?f(t):s(t)?l(t):void 0}function a(){return A.length=0,A}function c(t){return t&&"[object Object]"===Object.prototype.toString.call(t)}function s(t){return t&&"[object Array]"===Object.prototype.toString.call(t)}function f(t){return A.push(t),A}function l(t){var e=[]
a()
for(var r=0,n=t.length;n>r;r++)c(t[r])&&e.push(f(t[r]))
return e}function p(t){return t?d(A,t,M.searchStrategy,M).sort(M.sort):[]}function h(t){M=t||{},M.fuzzy=t.fuzzy||!1,M.limit=t.limit||10,M.searchStrategy=t.fuzzy?x:E,M.sort=t.sort||o,M.exclude=t.exclude||[]}function d(t,e,r,n){for(var i=[],o=0;o<t.length&&i.length<n.limit;o++){var u=y(t[o],e,r,n)
u&&i.push(u)}return i}function y(t,e,r,n){for(var i in t)if(t.hasOwnProperty(i)&&!v(t[i],n.exclude)&&r.matches(t[i],e))return t}function v(t,e){for(var r=0,n=e.length;n>r;r++){var i=e[r]
if(RegExp(i).test(t))return!0}return!1}function m(t,e){var r=g()
r.open("GET",t,!0),r.onreadystatechange=w(r,e),r.send()}function w(t,e){return function(){if(4===t.readyState&&200===t.status)try{e(null,JSON.parse(t.responseText))}catch(r){e(r,null)}}}function g(){return window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP")}function O(t,e){var r={}
for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n],void 0!==e[n]&&(r[n]=e[n]))
return r}function S(t){try{return t instanceof Object&&JSON.parse(JSON.stringify(t))?!0:!1}catch(e){return!1}}var b={compile:e,setOptions:t},j={}
j.pattern=/\{(.*?)\}/g,j.template="",j.middleware=function(){}
var T=r,x=new n,E=new i,z={put:u,clear:a,search:p,setOptions:h},A=[],M={}
M.fuzzy=!1,M.limit=10,M.searchStrategy=M.fuzzy?x:E,M.sort=o,M.exclude=[]
var L={load:m},q=function F(t){function e(t){return t?void 0!==t.required&&t.required instanceof Array:!1}if(!e(t))throw Error("-- OptionsValidator: required options missing")
if(!(this instanceof F))return new F(t)
var r=t.required
this.getRequiredOptions=function(){return r},this.validate=function(t){for(var e=[],n=0;n<r.length;n++){var i=r[n]
void 0===t[i]&&e.push(i)}return e}},C={merge:O,isJSON:S}
!function(t){function e(t){z.put(t),o()}function r(t){L.load(t,function(r,n){r&&f("failed to get JSON ("+t+")"),e(n)})}function n(){p.resultsContainer.innerHTML=""}function i(t){p.resultsContainer.innerHTML+=t}function o(){function t(t){var e=t.target||t.srcElement
s(t.which)&&(n(),h(function(){u(e.value)},p.debounceTime))}var e=p.searchInput
e.addEventListener?e.addEventListener("input",t):e.attachEvent&&e.attachEvent("onpropertychange",function(e){"value"===e.propertyName&&t(e)})}function u(t){c(t)&&(n(),a(z.search(t),t))}function a(t,e){var r=t.length
if(0===r)return i(p.noResultsText)
for(var n=0;r>n;n++)t[n].query=e,i(b.compile(t[n]))}function c(t){return t&&t.length>0}function s(t){for(var e=[13,16,20,37,38,39,40,91],r=0;r<e.length;r++)if(e[r]===t)return!1
return!0}function f(t){throw Error("SimpleJekyllSearch --- "+t)}var l,p={searchInput:null,resultsContainer:null,json:[],success:Function.prototype,searchResultTemplate:'<li><a href="{url}" title="{desc}">{title}</a></li>',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[]},h=function(t,e){e?(clearTimeout(l),l=setTimeout(t,e)):t.call()},d=["searchInput","resultsContainer","json"],y=q({required:d})
t.SimpleJekyllSearch=function(t){var n=y.validate(t)
n.length>0&&f("You must specify the following required options: "+d),p=C.merge(p,t),b.setOptions({template:p.searchResultTemplate,middleware:p.templateMiddleware}),z.setOptions({fuzzy:p.fuzzy,limit:p.limit,sort:p.sortMiddleware,exclude:p.exclude}),C.isJSON(p.json)?e(p.json):r(p.json)
var i={search:u}
return"function"==typeof p.success&&p.success.call(i),i}}(window)}()

View File

@ -6,7 +6,7 @@ title: 搜索
<h1>搜索</h1>
<form action="https://www.google.com/search">
<input type="hidden" name="as_sitesearch" value="mabbs.github.io" />
<p><center><input name="q" type="text" id="search-input" placeholder="Search blog posts.." /> <!--[if !IE]> --><img src="/images/loading.svg" alt="Loading..." id="search-loading" style="width:22px;vertical-align: bottom" /><!-- <![endif]--> <input type="submit" value="谷歌搜索" style="margin-left: 5px;" /></center></p>
<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>
</form>
<ul id="results-container"></ul>
<script>
@ -25,7 +25,6 @@ if (mykeyword) {
sbox.value = mykeyword;
}
</script>
<!--[if !IE]> -->
<script src="/assets/js/simple-jekyll-search.min.js"></script>
<script>
getSearchJSON(function(json){
@ -39,5 +38,4 @@ getSearchJSON(function(json){
sjs.search(mykeyword);
document.getElementById('search-loading').style.display = "none";
});
</script>
<!-- <![endif]-->
</script>