2 lines
7.9 KiB
JavaScript
2 lines
7.9 KiB
JavaScript
|
!function(){var u={},m={EXPIRE_KEY:"docsify.search.expires",INDEX_KEY:"docsify.search.index"};function h(e){return e.text||"table"!==e.type||(e.cells.unshift(e.header),e.text=e.cells.map(function(e){return e.join(" | ")}).join(" |\n ")),e.text}function f(e){return e.text||"list"!==e.type||(e.text=e.raw),e.text}function g(r,e,o,s){void 0===e&&(e="");var c,e=window.marked.lexer(e),d=window.Docsify.slugify,l={},p="";return e.forEach(function(e,n){if("heading"===e.type&&e.depth<=s){var t=function(e){void 0===e&&(e="");var a={};return{str:e=e&&e.replace(/^'/,"").replace(/'$/,"").replace(/(?:^|\s):([\w-]+:?)=?([\w-%]+)?/g,function(e,n,t){return-1===n.indexOf(":")?(a[n]=t&&t.replace(/"/g,"")||!0,""):e}).trim(),config:a}}(e.text),a=t.str,t=t.config;c=t.id?o.toURL(r,{id:d(t.id)}):o.toURL(r,{id:d((t=e.text,i={"&":"&","<":"<",">":">",'"':""","'":"'"},String(t).replace(/[&<>"']/g,function(e){return i[e]})))}),a&&(p=a.replace(/<!-- {docsify-ignore} -->/,"").replace(/{docsify-ignore}/,"").replace(/<!-- {docsify-ignore-all} -->/,"").replace(/{docsify-ignore-all}/,"").trim()),l[c]={slug:c,title:p,body:""}}else{if(0===n&&(c=o.toURL(r),l[c]={slug:c,title:"/"!==r?r.slice(1):"Home Page",body:e.text||""}),!c)return;l[c]?l[c].body?(e.text=h(e),e.text=f(e),l[c].body+="\n"+(e.text||"")):(e.text=h(e),e.text=f(e),l[c].body=l[c].body?l[c].body+e.text:e.text):l[c]={slug:c,title:"",body:""}}var i}),d.clear(),l}function p(e){return e&&e.normalize?e.normalize("NFD").replace(/[\u0300-\u036f]/g,""):e}function r(i,r){var t,a,n,e,o="auto"===i.paths,s=o?(t=r.router,a=[],Docsify.dom.findAll(".sidebar-nav a:not(.section-link):not([data-nosearch])").forEach(function(e){var n=e.href,e=e.getAttribute("href"),n=t.parse(n).path;n&&-1===a.indexOf(n)&&!Docsify.util.isAbsolutePath(e)&&a.push(n)}),a):i.paths,c="";s.length&&o&&i.pathNamespaces?(n=s[0],Array.isArray(i.pathNamespaces)?c=i.pathNamespaces.filter(function(e){return n.slice(0,e.length)===e})[0]||c:i.pathNamespaces instanceof RegExp&&((d=n.match(i.pathNamespaces))&&(c=d[0])),e=-1===s.indexOf(c+"/"),d=-1===s.indexOf(c+"/README"),e&&d&&s.unshift(c+"/")):-1===s.indexOf("/")&&-1===s.indexOf("/README")&&s.unshift("/");var d,l=((d=i.namespace)?m.EXPIRE_KEY+"/"+d:m.EXPIRE_KEY)+c,p=((d=i.namespace)?m.INDEX_KEY+"/"+d:m.INDEX_KEY)+c,c=localStorage.getItem(l)<Date.now();if(u=JSON.parse(localStorage.getItem(p)),c)u={};else if(!o)return;var h=s.length,f=0;s.forEach(function(a){return u[a]?f++:void Docsify.get(r.router.getFile(a),!1,r.config.requestHeaders).then(function(e){var n,t;u[a]=g(a,e,r.router,i.depth),h===++f&&(n=i.maxAge,t=l,e=p,localStorage.setItem(t,Date.now()+n),localStorage.setItem(e,JSON.stringify(u)))})})}var o,s="";function c(e){var n=Docsify.dom.find("div.search"),t=Docsify.dom.find(n,".results-panel"),a=Docsify.dom.find(n,".clear-button"),i=Docsify.dom.find(".sidebar-nav"),n=Docsify.dom.find(".app-name");if(!e)return t.classList.remove("show"),a.classList.remove("show"),t.innerHTML="",void(o.hideOtherSidebarContent&&(i.classList.remove("hide"),n.classList.remove("hide")));var e=function(e){var n=[],t=[];Object.keys(u).forEach(function(n){t=t.concat(Object.keys(u[n]).map(function(e){return u[n][e]}))});var a=(e=e.trim()).split(/[\s\-,\\/]+/);1!==a.length&&(a=[].concat(e,a));for(var i=0;i<t.length;i++)!function(e){var e=t[e],r=0,o="",s="",c="",d=e.title&&e.title.trim(),l=e.body&&e.body.trim(),e=e.slug||"";d&&(a.forEach(function(e){var n,t=new RegExp(p(e).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&"),"gi"),a=-1,i=-1;s=d?p(d):d,c=l?p(l):l,a=d?s.search(t):-1,i=l?c.search(t):-1,(0<=a||0<=i)&&(r+=0<=a?3:0<=i?2:0,i<0&&(i=0),a=(a=n=0)==(n=i<11?0:i-10)?70:i+e.length+60,l&&a>l.length&&(a=l.length),t="..."+c.substring(n,a).replace(t,function(e){return'<em class="search-keyword">'+e+"</em>"})+"...",o+=t)}),0<r&&(e={title:s,content:l?o:"",url:e,score:r},n.push(e)))}(i);return n.sort(function(e,n){return n.score-e.score})}(e),r="";e.forEach(function(e){r+='<div class="matching-post">\n<a href="'+e.url+'">\n<h2>'+e.title+"</h2>\n<p>"+e.content+"</p>\n</a>\n</div>"}),t.classList.add("show"),a.classLis
|