/** * ghostHunter - 0.6.0 * Copyright (C) 2014 Jamal Neufeld (jamal@i11u.me) * MIT Licensed * @license */ !function(e){var t,r;!function(){var e,t,r,i,n,s,o,a,u,l,h,d,c,f,p,g,m,y,x,v,w,b,k,S,Q,L,_,T,P=function(e){var t=new P.Builder;return t.pipeline.add(P.trimmer,P.stopWordFilter,P.stemmer),t.searchPipeline.add(P.stemmer),e.call(t,t),t.build()};P.version="2.1.5" /*! * lunr.utils * Copyright (C) 2017 Oliver Nightingale */,P.utils={},P.utils.warn=(e=this,function(t){e.console&&console.warn&&console.warn(t)}),P.utils.asString=function(e){return null==e?"":e.toString()},P.FieldRef=function(e,t,r){this.docRef=e,this.fieldName=t,this._stringValue=r},P.FieldRef.joiner="/",P.FieldRef.fromString=function(e){var t=e.indexOf(P.FieldRef.joiner);if(-1===t)throw"malformed field ref string";var r=e.slice(0,t),i=e.slice(t+1);return new P.FieldRef(i,r,e)},P.FieldRef.prototype.toString=function(){return null==this._stringValue&&(this._stringValue=this.fieldName+P.FieldRef.joiner+this.docRef),this._stringValue},P.idf=function(e,t){var r=0;for(var i in e)"_index"!=i&&(r+=Object.keys(e[i]).length);var n=(t-r+.5)/(r+.5);return Math.log(1+Math.abs(n))},P.Token=function(e,t){this.str=e||"",this.metadata=t||{}},P.Token.prototype.toString=function(){return this.str},P.Token.prototype.update=function(e){return this.str=e(this.str,this.metadata),this},P.Token.prototype.clone=function(e){return e=e||function(e){return e},new P.Token(e(this.str,this.metadata),this.metadata)} /*! * lunr.tokenizer * Copyright (C) 2017 Oliver Nightingale */,P.tokenizer=function(e){if(null==e||null==e)return[];if(Array.isArray(e))return e.map((function(e){return new P.Token(P.utils.asString(e).toLowerCase())}));for(var t=e.toString().trim().toLowerCase(),r=t.length,i=[],n=0,s=0;n<=r;n++){var o=n-s;(t.charAt(n).match(P.tokenizer.separator)||n==r)&&(o>0&&i.push(new P.Token(t.slice(s,n),{position:[s,o],index:i.length})),s=n+1)}return i},P.tokenizer.separator=/[\s\-]+/ /*! * lunr.Pipeline * Copyright (C) 2017 Oliver Nightingale */,P.Pipeline=function(){this._stack=[]},P.Pipeline.registeredFunctions=Object.create(null),P.Pipeline.registerFunction=function(e,t){t in this.registeredFunctions&&P.utils.warn("Overwriting existing registered function: "+t),e.label=t,P.Pipeline.registeredFunctions[e.label]=e},P.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions||P.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},P.Pipeline.load=function(e){var t=new P.Pipeline;return e.forEach((function(e){var r=P.Pipeline.registeredFunctions[e];if(!r)throw new Error("Cannot load unregistered function: "+e);t.add(r)})),t},P.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach((function(e){P.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)}),this)},P.Pipeline.prototype.after=function(e,t){P.Pipeline.warnIfFunctionNotRegistered(t);var r=this._stack.indexOf(e);if(-1==r)throw new Error("Cannot find existingFn");r+=1,this._stack.splice(r,0,t)},P.Pipeline.prototype.before=function(e,t){P.Pipeline.warnIfFunctionNotRegistered(t);var r=this._stack.indexOf(e);if(-1==r)throw new Error("Cannot find existingFn");this._stack.splice(r,0,t)},P.Pipeline.prototype.remove=function(e){var t=this._stack.indexOf(e);-1!=t&&this._stack.splice(t,1)},P.Pipeline.prototype.run=function(e){for(var t=this._stack.length,r=0;r1&&(se&&(r=n),s!=e);)i=r-t,n=t+Math.floor(i/2),s=this.elements[2*n];return s==e||s>e?2*n:sa?l+=2:o==a&&(t+=r[u+1]*i[l+1],u+=2,l+=2);return t},P.Vector.prototype.similarity=function(e){return this.dot(e)/(this.magnitude()*e.magnitude())},P.Vector.prototype.toArray=function(){for(var e=new Array(this.elements.length/2),t=1,r=0;t0)(s=a.str.charAt(0))in a.node.edges?n=a.node.edges[s]:(n=new P.TokenSet,a.node.edges[s]=n),1==a.str.length?n.final=!0:i.push({node:n,editsRemaining:a.editsRemaining,str:a.str.slice(1)});if(a.editsRemaining>0&&a.str.length>1)(s=a.str.charAt(1))in a.node.edges?o=a.node.edges[s]:(o=new P.TokenSet,a.node.edges[s]=o),a.str.length<=2?o.final=!0:i.push({node:o,editsRemaining:a.editsRemaining-1,str:a.str.slice(2)});if(a.editsRemaining>0&&1==a.str.length&&(a.node.final=!0),a.editsRemaining>0&&a.str.length>=1){if("*"in a.node.edges)var u=a.node.edges["*"];else{u=new P.TokenSet;a.node.edges["*"]=u}1==a.str.length?u.final=!0:i.push({node:u,editsRemaining:a.editsRemaining-1,str:a.str.slice(1)})}if(a.editsRemaining>0){if("*"in a.node.edges)var l=a.node.edges["*"];else{l=new P.TokenSet;a.node.edges["*"]=l}0==a.str.length?l.final=!0:i.push({node:l,editsRemaining:a.editsRemaining-1,str:a.str})}if(a.editsRemaining>0&&a.str.length>1){var h,d=a.str.charAt(0),c=a.str.charAt(1);c in a.node.edges?h=a.node.edges[c]:(h=new P.TokenSet,a.node.edges[c]=h),1==a.str.length?h.final=!0:i.push({node:h,editsRemaining:a.editsRemaining-1,str:d+a.str.slice(2)})}}return r},P.TokenSet.fromString=function(e){for(var t=new P.TokenSet,r=t,i=!1,n=0,s=e.length;n=e;t--){var r=this.uncheckedNodes[t],i=r.child.toString();i in this.minimizedNodes?r.parent.edges[r.char]=this.minimizedNodes[i]:(r.child._str=i,this.minimizedNodes[i]=r.child),this.uncheckedNodes.pop()}} /*! * lunr.Index * Copyright (C) 2017 Oliver Nightingale */,P.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},P.Index.prototype.search=function(e){return this.query((function(t){new P.QueryParser(e,t).parse()}))},P.Index.prototype.query=function(e){var t=new P.Query(this.fields),r=Object.create(null),i=Object.create(null),n=Object.create(null);e.call(t,t);for(var s=0;s1?1:e},P.Builder.prototype.k1=function(e){this._k1=e},P.Builder.prototype.add=function(e){var t=e[this._ref];this.documentCount+=1;for(var r=0;r=this.length)return P.QueryLexer.EOS;var e=this.str.charAt(this.pos);return this.pos+=1,e},P.QueryLexer.prototype.width=function(){return this.pos-this.start},P.QueryLexer.prototype.ignore=function(){this.start==this.pos&&(this.pos+=1),this.start=this.pos},P.QueryLexer.prototype.backup=function(){this.pos-=1},P.QueryLexer.prototype.acceptDigitRun=function(){var e,t;do{t=(e=this.next()).charCodeAt(0)}while(t>47&&t<58);e!=P.QueryLexer.EOS&&this.backup()},P.QueryLexer.prototype.more=function(){return this.pos1&&(e.backup(),e.emit(P.QueryLexer.TERM)),e.ignore(),e.more())return P.QueryLexer.lexText},P.QueryLexer.lexEditDistance=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(P.QueryLexer.EDIT_DISTANCE),P.QueryLexer.lexText},P.QueryLexer.lexBoost=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(P.QueryLexer.BOOST),P.QueryLexer.lexText},P.QueryLexer.lexEOS=function(e){e.width()>0&&e.emit(P.QueryLexer.TERM)},P.QueryLexer.termSeparator=P.tokenizer.separator,P.QueryLexer.lexText=function(e){for(;;){var t=e.next();if(t==P.QueryLexer.EOS)return P.QueryLexer.lexEOS;if(92!=t.charCodeAt(0)){if(":"==t)return P.QueryLexer.lexField;if("~"==t)return e.backup(),e.width()>0&&e.emit(P.QueryLexer.TERM),P.QueryLexer.lexEditDistance;if("^"==t)return e.backup(),e.width()>0&&e.emit(P.QueryLexer.TERM),P.QueryLexer.lexBoost;if(t.match(P.QueryLexer.termSeparator))return P.QueryLexer.lexTerm}else e.escapeCharacter()}},P.QueryParser=function(e,t){this.lexer=new P.QueryLexer(e),this.query=t,this.currentClause={},this.lexemeIdx=0},P.QueryParser.prototype.parse=function(){this.lexer.run(),this.lexemes=this.lexer.lexemes;for(var e=P.QueryParser.parseFieldOrTerm;e;)e=e(this);return this.query},P.QueryParser.prototype.peekLexeme=function(){return this.lexemes[this.lexemeIdx]},P.QueryParser.prototype.consumeLexeme=function(){var e=this.peekLexeme();return this.lexemeIdx+=1,e},P.QueryParser.prototype.nextClause=function(){var e=this.currentClause;this.query.clause(e),this.currentClause={}},P.QueryParser.parseFieldOrTerm=function(e){var t=e.peekLexeme();if(null!=t)switch(t.type){case P.QueryLexer.FIELD:return P.QueryParser.parseField;case P.QueryLexer.TERM:return P.QueryParser.parseTerm;default:var r="expected either a field or a term, found "+t.type;throw t.str.length>=1&&(r+=" with value '"+t.str+"'"),new P.QueryParseError(r,t.start,t.end)}},P.QueryParser.parseField=function(e){var t=e.consumeLexeme();if(null!=t){if(-1==e.query.allFields.indexOf(t.str)){var r=e.query.allFields.map((function(e){return"'"+e+"'"})).join(", "),i="unrecognised field '"+t.str+"', possible fields: "+r;throw new P.QueryParseError(i,t.start,t.end)}e.currentClause.fields=[t.str];var n=e.peekLexeme();if(null==n){i="expecting term, found nothing";throw new P.QueryParseError(i,t.start,t.end)}switch(n.type){case P.QueryLexer.TERM:return P.QueryParser.parseTerm;default:i="expecting term, found '"+n.type+"'";throw new P.QueryParseError(i,n.start,n.end)}}},P.QueryParser.parseTerm=function(e){var t=e.consumeLexeme();if(null!=t){e.currentClause.term=t.str.toLowerCase(),-1!=t.str.indexOf("*")&&(e.currentClause.usePipeline=!1);var r=e.peekLexeme();if(null!=r)switch(r.type){case P.QueryLexer.TERM:return e.nextClause(),P.QueryParser.parseTerm;case P.QueryLexer.FIELD:return e.nextClause(),P.QueryParser.parseField;case P.QueryLexer.EDIT_DISTANCE:return P.QueryParser.parseEditDistance;case P.QueryLexer.BOOST:return P.QueryParser.parseBoost;default:var i="Unexpected lexeme type '"+r.type+"'";throw new P.QueryParseError(i,r.start,r.end)}else e.nextClause()}},P.QueryParser.parseEditDistance=function(e){var t=e.consumeLexeme();if(null!=t){var r=parseInt(t.str,10);if(isNaN(r)){var i="edit distance must be numeric";throw new P.QueryParseError(i,t.start,t.end)}e.currentClause.editDistance=r;var n=e.peekLexeme();if(null!=n)switch(n.type){case P.QueryLexer.TERM:return e.nextClause(),P.QueryParser.parseTerm;case P.QueryLexer.FIELD:return e.nextClause(),P.QueryParser.parseField;case P.QueryLexer.EDIT_DISTANCE:return P.QueryParser.parseEditDistance;case P.QueryLexer.BOOST:return P.QueryParser.parseBoost;default:i="Unexpected lexeme type '"+n.type+"'";throw new P.QueryParseError(i,n.start,n.end)}else e.nextClause()}},P.QueryParser.parseBoost=function(e){var t=e.consumeLexeme();if(null!=t){var r=parseInt(t.str,10);if(isNaN(r)){var i="boost must be numeric";throw new P.QueryParseError(i,t.start,t.end)}e.currentClause.boost=r;var n=e.peekLexeme();if(null!=n)switch(n.type){case P.QueryLexer.TERM:return e.nextClause(),P.QueryParser.parseTerm;case P.QueryLexer.FIELD:return e.nextClause(),P.QueryParser.parseField;case P.QueryLexer.EDIT_DISTANCE:return P.QueryParser.parseEditDistance;case P.QueryLexer.BOOST:return P.QueryParser.parseBoost;default:i="Unexpected lexeme type '"+n.type+"'";throw new P.QueryParseError(i,n.start,n.end)}else e.nextClause()}},_=this,T=function(){return P},"function"==typeof define&&define.amd?define(T):"object"==typeof exports?module.exports=T():_.lunr=T()}(),t=this,r=function(e){function t(e,t){var r,i;for(r=-1,i=e.length;++r0?t[r][i-1]:Number.MAX_VALUE,s=r>0?t[r-1][i]:Number.MAX_VALUE,o=i>0&&r>0?t[r-1][i-1]:Number.MAX_VALUE,(a=Math.min(n,s,o))===o?(o

{{title}}

{{prettyPubDate}}

",info_template:"

Number of posts found: {{amount}}

",displaySearchInfo:!0,zeroResultsInfo:!0,before:!1,onComplete:!1,filterfields:!1,subpath:"",item_preprocessor:!1,indexing_start:!1,indexing_end:!1,includebodysearch:!1};var i=function(e){return e.replace(/^\//,"").replace(/\//g,"-")},n=null,s=function(){e(".gh-search-item").each((function(){var e=this.getAttribute("id").replace(/^new-/,"");this.setAttribute("id",e)}))},o=function(e,t,r){for(var i=0,n=r.length;inew Date(n.latestPost).getTime()&&(n.latestPost=e.updated_at);var t=e.tags.map((function(e){return e.name}));null==e.meta_description&&(e.meta_description="");var r=t.join(", ");r.length<1&&(r="undefined");var i={id:String(e.id),title:String(e.title),description:String(e.custom_excerpt),pubDate:String(e.published_at),tag:r};n.includebodysearch&&(i.plaintext=String(e.plaintext)),this.add(i);var s,o,a=n.subpath+e.url;n.blogData[e.id]={title:e.title,description:e.custom_excerpt,pubDate:(s=i.pubDate,o=new Date(s),o.getDate()+" "+["January","February","March","April","May","June","July","August","September","October","November","December"][o.getMonth()]+" "+o.getFullYear()),link:a,tags:t},n.item_preprocessor&&Object.assign(n.blogData[e.id],n.item_preprocessor(e))}),this)}));try{var r=i(n.subpath);localStorage.setItem("ghost_"+r+"_lunrIndex",JSON.stringify(n.index)),localStorage.setItem("ghost_"+r+"_blogData",JSON.stringify(n.blogData)),localStorage.setItem("ghost_"+r+"_latestPost",n.latestPost)}catch(e){console.warn("ghostHunter: save to localStorage failed: "+e)}n.indexing_end&&n.indexing_end(),n.isInit=!0}))},u={isInit:!1,init:function(e,t){var r=this;if(r.target=e,Object.assign(this,t),t.onPageLoad){window.setTimeout((function(){r.loadAPI()}),1)}else e.focus((function(){r.loadAPI()}));e.closest("form").submit((function(t){t.preventDefault(),r.find(e.val())})),t.onKeyUp&&(e.keydown((function(e){if(13===e.which)return!1})),e.keyup((function(t){r.find(e.val())})))},loadAPI:function(){if(!this.isInit){this.indexing_start&&this.indexing_start();try{var t=i(this.subpath);this.index=localStorage.getItem("ghost_"+t+"_lunrIndex"),this.blogData=localStorage.getItem("ghost_"+t+"_blogData"),this.latestPost=localStorage.getItem("ghost_"+t+"_latestPost"),this.latestPost&&this.index&&this.blogData&&(this.latestPost=this.latestPost,this.index=lunr.Index.load(JSON.parse(this.index)),this.blogData=JSON.parse(this.blogData),this.isInit=!0)}catch(e){console.warn("ghostHunter: retrieve from localStorage failed: "+e)}}if(this.isInit){this.latestPost.replace(/\..*/,"").replace(/T/," ");var r=(ghost_root_url||"/ghost/api/v2")+"/content/posts/?key="+ghosthunter_key+"&limit=all&fields=id&filter=updated_at:>'"+this.latestPost.replace(/\..*/,"").replace(/T/," ")+"'",n=this;e.get(r).done((function(e){e.posts.length>0?a.call(n):(n.indexing_end&&n.indexing_end(),n.isInit=!0)}))}else a.call(this)},find:function(t){clearTimeout(n),t||(t=""),t=t.toLowerCase(),n=setTimeout(function(){for(var r=[],i=t.split(/\s+/),n=0,a=i.length;n1){var l=r[0];r=r.slice(1);for(n=l.length-1;n>-1;n--){var h=l[n].ref;for(j=0,jlen=r.length;j0?p.children().eq(0).replaceWith(this.format(this.info_template,{amount:l.length})):p.append(this.format(this.info_template,{amount:l.length}))),this.before&&this.before();for(n=0;n