diff --git a/_includes/header.html b/_includes/header.html index 14e6f55ef..7811a6367 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -39,11 +39,10 @@ - diff --git a/_sass/minima/_search-page.scss b/_sass/minima/_search-page.scss index 591dd5a35..ecc42f35d 100644 --- a/_sass/minima/_search-page.scss +++ b/_sass/minima/_search-page.scss @@ -13,20 +13,24 @@ form { input { - display: block; - width: 100%; - height: 60px; - border: 1px solid rgba(var(--front), 0.2); - font-size: 27px; - padding-left: 20px; - padding-right: 20px; - box-sizing: border-box; - - &:active, - &:focus { - border-color: var(--primary-color); - outline: none; - } + display: block; + width: 100%; + height: 60px; + border: 1px solid rgba(var(--front), 0.2); + font-size: 27px; + padding-left: 20px; + padding-right: 20px; + box-sizing: border-box; + + &:active, + &:focus { + border-color: var(--primary-color); + outline: none; + } + + &::placeholder { + color: #cccccc; + } } } @@ -36,45 +40,110 @@ margin: 20px 0 0 0; li { - h3 { - margin-top: 0; - margin-bottom: 0; - font-size: 18px; - line-height: 1.2; - color: var(--frontHex); - transition: color 100ms $ease; + border-bottom: 1px solid #ededed; + + h3 { + margin-top: 0; + margin-bottom: 0; + font-size: 18px; + line-height: 1.2; + color: var(--frontHex); + transition: color 100ms $ease; + + span { + margin-left: 5px; + vertical-align: middle; + display: inline-block; + width: 8px; + height: 8px; + border-radius: 4px; + transform: translateY(-1px); } + } - a { - display: block; - padding: 15px 0; - transition: background-color 100ms $ease; - - p { - margin-top: 5px; - margin-bottom: 0; - font-size: 16px; - line-height: 1.4; - color: rgba(var(--front), 0.7); - } + a { + display: block; + padding: 15px 0; + transition: background-color 100ms $ease; + + p { + margin-top: 5px; + margin-bottom: 0; + font-size: 16px; + line-height: 1.4; + color: rgba(var(--front), 0.7); + } - &:hover { - text-decoration: none; - background-color: rgba(var(--primary-color-rgb), 0.05); + &:hover { + text-decoration: none; + background-color: rgba(var(--primary-color-rgb), 0.05); - h3 { - color: var(--primary-color); - } + h3 { + color: var(--primary-color); } } + } + + &.no-results { + padding: 15px 0; + } + } + } + + #search-tips { + padding: 15px 0; + + button { + appearance: none; + background-color: transparent; + border-width: 0; + padding: 0; + display: flex; + gap: 3px; + font-size: 15px; + align-items: center; + transition: all 150ms $ease; - > h3 { - padding: 15px 0; + svg { + width: 14px; + height: 14px; + transition: all 150ms $ease; + } + + &:hover { + color: var(--primary-color); + cursor: pointer; + } + + &[aria-expanded="true"] { + svg { + transform: rotate(90deg); } + } + } + } + + #search-tips-content { + p { + font-size: 15px; + } - & + li { - border-top: 1px solid #ededed; + ul { + margin-top: 5px; + + li { + font-size: 15px; + + em { + font-style: normal; + font-weight: 500; + color: var(--front); } + } + + & + p { + margin-top: 5px; + } } } } diff --git a/_sass/minima/_site-header.scss b/_sass/minima/_site-header.scss index 19e66b4e3..a869f999c 100644 --- a/_sass/minima/_site-header.scss +++ b/_sass/minima/_site-header.scss @@ -188,6 +188,16 @@ line-height: 1.2; color: var(--frontHex); transition: color 100ms $ease; + + span { + margin-left: 5px; + vertical-align: middle; + display: inline-block; + width: 8px; + height: 8px; + border-radius: 4px; + transform: translateY(-1px); + } } a { diff --git a/js/lunr.min.js b/js/lunr.min.js index 4fd086e7c..cdc94cd39 100644 --- a/js/lunr.min.js +++ b/js/lunr.min.js @@ -1,6 +1,6 @@ /** - * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.7.1 - * Copyright (C) 2016 Oliver Nightingale + * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.9 + * Copyright (C) 2020 Oliver Nightingale * @license MIT */ -!function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.7.1",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.utils.asString=function(t){return void 0===t||null===t?"":t.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].splice(n,1),this.events[t].length||delete this.events[t]}},t.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},t.EventEmitter.prototype.hasHandler=function(t){return t in this.events},t.tokenizer=function(e){return arguments.length&&null!=e&&void 0!=e?Array.isArray(e)?e.map(function(e){return t.utils.asString(e).toLowerCase()}):e.toString().trim().toLowerCase().split(t.tokenizer.seperator):[]},t.tokenizer.seperator=/[\s\-]+/,t.tokenizer.load=function(t){var e=this.registeredFunctions[t];if(!e)throw new Error("Cannot load un-registered function: "+t);return e},t.tokenizer.label="default",t.tokenizer.registeredFunctions={"default":t.tokenizer},t.tokenizer.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing tokenizer: "+n),e.label=n,this.registeredFunctions[n]=e},t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.registeredFunctions[e];if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");this._stack.splice(i,0,n)},t.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},t.Pipeline.prototype.run=function(t){for(var e=[],n=t.length,i=this._stack.length,r=0;n>r;r++){for(var o=t[r],s=0;i>s&&(o=this._stack[s](o,r,t),void 0!==o&&""!==o);s++);void 0!==o&&""!==o&&e.push(o)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(en.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t1;){if(o===t)return r;t>o&&(e=r),o>t&&(n=r),i=n-e,r=e+Math.floor(i/2),o=this.elements[r]}return o===t?r:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,r=e+Math.floor(i/2),o=this.elements[r];i>1;)t>o&&(e=r),o>t&&(n=r),i=n-e,r=e+Math.floor(i/2),o=this.elements[r];return o>t?r:t>o?r+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,r=0,o=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>o-1||r>s-1)break;a[i]!==h[r]?a[i]h[r]&&r++:(n.add(a[i]),i++,r++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone();for(var r=0,o=n.toArray();rp;p++)c[p]===a&&d++;h+=d/f*l.boost}}this.tokenStore.add(a,{ref:o,tf:h})}n&&this.eventEmitter.emit("add",e,this)},t.Index.prototype.remove=function(t,e){var n=t[this._ref],e=void 0===e?!0:e;if(this.documentStore.has(n)){var i=this.documentStore.get(n);this.documentStore.remove(n),i.forEach(function(t){this.tokenStore.remove(t,n)},this),e&&this.eventEmitter.emit("remove",t,this)}},t.Index.prototype.update=function(t,e){var e=void 0===e?!0:e;this.remove(t,!1),this.add(t,!1),e&&this.eventEmitter.emit("update",t,this)},t.Index.prototype.idf=function(t){var e="@"+t;if(Object.prototype.hasOwnProperty.call(this._idfCache,e))return this._idfCache[e];var n=this.tokenStore.count(t),i=1;return n>0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(this.tokenizerFn(e)),i=new t.Vector,r=[],o=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*o,h=this,u=this.tokenStore.expand(e).reduce(function(n,r){var o=h.corpusTokens.indexOf(r),s=h.idf(r),u=1,l=new t.SortedSet;if(r!==e){var c=Math.max(3,r.length-e.length);u=1/Math.log(c)}o>-1&&i.insert(o,a*s*u);for(var f=h.tokenStore.get(r),d=Object.keys(f),p=d.length,v=0;p>v;v++)l.add(f[d[v]].ref);return n.union(l)},new t.SortedSet);r.push(u)},this);var a=r.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,r=new t.Vector,o=0;i>o;o++){var s=n.elements[o],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);r.insert(this.corpusTokens.indexOf(s),a*h)}return r},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,tokenizer:this.tokenizerFn.label,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",r=n+"[^aeiouy]*",o=i+"[aeiou]*",s="^("+r+")?"+o+r,a="^("+r+")?"+o+r+"("+o+")?$",h="^("+r+")?"+o+r+o+r,u="^("+r+")?"+i,l=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(u),p=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,g=/^(.+?)eed$/,m=/^(.+?)(ed|ing)$/,y=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),k=new RegExp("^"+r+i+"[^aeiouwxy]$"),x=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,F=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,_=/^(.+?)(s|t)(ion)$/,z=/^(.+?)e$/,O=/ll$/,P=new RegExp("^"+r+i+"[^aeiouwxy]$"),T=function(n){var i,r,o,s,a,h,u;if(n.length<3)return n;if(o=n.substr(0,1),"y"==o&&(n=o.toUpperCase()+n.substr(1)),s=p,a=v,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=g,a=m,s.test(n)){var T=s.exec(n);s=l,s.test(T[1])&&(s=y,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,u=k,a.test(n)?n+="e":h.test(n)?(s=y,n=n.replace(s,"")):u.test(n)&&(n+="e"))}if(s=x,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],r=T[2],s=l,s.test(i)&&(n=i+t[r])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],r=T[2],s=l,s.test(i)&&(n=i+e[r])}if(s=F,a=_,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=z,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=P,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=O,a=c,s.test(n)&&a.test(n)&&(s=y,n=n.replace(s,"")),"y"==o&&(n=o.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.generateStopWordFilter=function(t){var e=t.reduce(function(t,e){return t[e]=e,t},{});return function(t){return t&&e[t]!==t?t:void 0}},t.stopWordFilter=t.generateStopWordFilter(["a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"]),t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){return t.replace(/^\W+/,"").replace(/\W+$/,"")},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t.charAt(0),r=t.slice(1);return i in n||(n[i]={docs:{}}),0===r.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(r,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;n0){var c=e.utils.clone(r)||{};c.position=[a,l],c.index=s.length,s.push(new e.Token(i.slice(a,o),c))}a=o+1}}return s},e.tokenizer.separator=/[\s\-]+/,e.Pipeline=function(){this._stack=[]},e.Pipeline.registeredFunctions=Object.create(null),e.Pipeline.registerFunction=function(t,r){r in this.registeredFunctions&&e.utils.warn("Overwriting existing registered function: "+r),t.label=r,e.Pipeline.registeredFunctions[t.label]=t},e.Pipeline.warnIfFunctionNotRegistered=function(t){var r=t.label&&t.label in this.registeredFunctions;r||e.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",t)},e.Pipeline.load=function(t){var r=new e.Pipeline;return t.forEach(function(t){var i=e.Pipeline.registeredFunctions[t];if(!i)throw new Error("Cannot load unregistered function: "+t);r.add(i)}),r},e.Pipeline.prototype.add=function(){var t=Array.prototype.slice.call(arguments);t.forEach(function(t){e.Pipeline.warnIfFunctionNotRegistered(t),this._stack.push(t)},this)},e.Pipeline.prototype.after=function(t,r){e.Pipeline.warnIfFunctionNotRegistered(r);var i=this._stack.indexOf(t);if(i==-1)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,r)},e.Pipeline.prototype.before=function(t,r){e.Pipeline.warnIfFunctionNotRegistered(r);var i=this._stack.indexOf(t);if(i==-1)throw new Error("Cannot find existingFn");this._stack.splice(i,0,r)},e.Pipeline.prototype.remove=function(e){var t=this._stack.indexOf(e);t!=-1&&this._stack.splice(t,1)},e.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?2*n:s>e?2*n:sa?l+=2:o==a&&(t+=r[u+1]*i[l+1],u+=2,l+=2);return t},e.Vector.prototype.similarity=function(e){return this.dot(e)/this.magnitude()||0},e.Vector.prototype.toArray=function(){for(var e=new Array(this.elements.length/2),t=1,r=0;t0){var o,a=s.str.charAt(0);a in s.node.edges?o=s.node.edges[a]:(o=new e.TokenSet,s.node.edges[a]=o),1==s.str.length&&(o["final"]=!0),n.push({node:o,editsRemaining:s.editsRemaining,str:s.str.slice(1)})}if(0!=s.editsRemaining){if("*"in s.node.edges)var u=s.node.edges["*"];else{var u=new e.TokenSet;s.node.edges["*"]=u}if(0==s.str.length&&(u["final"]=!0),n.push({node:u,editsRemaining:s.editsRemaining-1,str:s.str}),s.str.length>1&&n.push({node:s.node,editsRemaining:s.editsRemaining-1,str:s.str.slice(1)}),1==s.str.length&&(s.node["final"]=!0),s.str.length>=1){if("*"in s.node.edges)var l=s.node.edges["*"];else{var l=new e.TokenSet;s.node.edges["*"]=l}1==s.str.length&&(l["final"]=!0),n.push({node:l,editsRemaining:s.editsRemaining-1,str:s.str.slice(1)})}if(s.str.length>1){var c,h=s.str.charAt(0),d=s.str.charAt(1);d in s.node.edges?c=s.node.edges[d]:(c=new e.TokenSet,s.node.edges[d]=c),1==s.str.length&&(c["final"]=!0),n.push({node:c,editsRemaining:s.editsRemaining-1,str:h+s.str.slice(2)})}}}return i},e.TokenSet.fromString=function(t){for(var r=new e.TokenSet,i=r,n=0,s=t.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()}},e.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},e.Index.prototype.search=function(t){return this.query(function(r){var i=new e.QueryParser(t,r);i.parse()})},e.Index.prototype.query=function(t){for(var r=new e.Query(this.fields),i=Object.create(null),n=Object.create(null),s=Object.create(null),o=Object.create(null),a=Object.create(null),u=0;u1?this._b=1:this._b=e},e.Builder.prototype.k1=function(e){this._k1=e},e.Builder.prototype.add=function(t,r){var i=t[this._ref],n=Object.keys(this._fields);this._documents[i]=r||{},this.documentCount+=1;for(var s=0;s=this.length)return e.QueryLexer.EOS;var t=this.str.charAt(this.pos);return this.pos+=1,t},e.QueryLexer.prototype.width=function(){return this.pos-this.start},e.QueryLexer.prototype.ignore=function(){this.start==this.pos&&(this.pos+=1),this.start=this.pos},e.QueryLexer.prototype.backup=function(){this.pos-=1},e.QueryLexer.prototype.acceptDigitRun=function(){var t,r;do t=this.next(),r=t.charCodeAt(0);while(r>47&&r<58);t!=e.QueryLexer.EOS&&this.backup()},e.QueryLexer.prototype.more=function(){return this.pos1&&(t.backup(),t.emit(e.QueryLexer.TERM)),t.ignore(),t.more())return e.QueryLexer.lexText},e.QueryLexer.lexEditDistance=function(t){return t.ignore(),t.acceptDigitRun(),t.emit(e.QueryLexer.EDIT_DISTANCE),e.QueryLexer.lexText},e.QueryLexer.lexBoost=function(t){return t.ignore(),t.acceptDigitRun(),t.emit(e.QueryLexer.BOOST),e.QueryLexer.lexText},e.QueryLexer.lexEOS=function(t){t.width()>0&&t.emit(e.QueryLexer.TERM)},e.QueryLexer.termSeparator=e.tokenizer.separator,e.QueryLexer.lexText=function(t){for(;;){var r=t.next();if(r==e.QueryLexer.EOS)return e.QueryLexer.lexEOS;if(92!=r.charCodeAt(0)){if(":"==r)return e.QueryLexer.lexField;if("~"==r)return t.backup(),t.width()>0&&t.emit(e.QueryLexer.TERM),e.QueryLexer.lexEditDistance;if("^"==r)return t.backup(),t.width()>0&&t.emit(e.QueryLexer.TERM),e.QueryLexer.lexBoost;if("+"==r&&1===t.width())return t.emit(e.QueryLexer.PRESENCE),e.QueryLexer.lexText;if("-"==r&&1===t.width())return t.emit(e.QueryLexer.PRESENCE),e.QueryLexer.lexText;if(r.match(e.QueryLexer.termSeparator))return e.QueryLexer.lexTerm}else t.escapeCharacter()}},e.QueryParser=function(t,r){this.lexer=new e.QueryLexer(t),this.query=r,this.currentClause={},this.lexemeIdx=0},e.QueryParser.prototype.parse=function(){this.lexer.run(),this.lexemes=this.lexer.lexemes;for(var t=e.QueryParser.parseClause;t;)t=t(this);return this.query},e.QueryParser.prototype.peekLexeme=function(){return this.lexemes[this.lexemeIdx]},e.QueryParser.prototype.consumeLexeme=function(){var e=this.peekLexeme();return this.lexemeIdx+=1,e},e.QueryParser.prototype.nextClause=function(){var e=this.currentClause;this.query.clause(e),this.currentClause={}},e.QueryParser.parseClause=function(t){var r=t.peekLexeme();if(void 0!=r)switch(r.type){case e.QueryLexer.PRESENCE:return e.QueryParser.parsePresence;case e.QueryLexer.FIELD:return e.QueryParser.parseField;case e.QueryLexer.TERM:return e.QueryParser.parseTerm;default:var i="expected either a field or a term, found "+r.type;throw r.str.length>=1&&(i+=" with value '"+r.str+"'"),new e.QueryParseError(i,r.start,r.end)}},e.QueryParser.parsePresence=function(t){var r=t.consumeLexeme();if(void 0!=r){switch(r.str){case"-":t.currentClause.presence=e.Query.presence.PROHIBITED;break;case"+":t.currentClause.presence=e.Query.presence.REQUIRED;break;default:var i="unrecognised presence operator'"+r.str+"'";throw new e.QueryParseError(i,r.start,r.end)}var n=t.peekLexeme();if(void 0==n){var i="expecting term or field, found nothing";throw new e.QueryParseError(i,r.start,r.end)}switch(n.type){case e.QueryLexer.FIELD:return e.QueryParser.parseField;case e.QueryLexer.TERM:return e.QueryParser.parseTerm;default:var i="expecting term or field, found '"+n.type+"'";throw new e.QueryParseError(i,n.start,n.end)}}},e.QueryParser.parseField=function(t){var r=t.consumeLexeme();if(void 0!=r){if(t.query.allFields.indexOf(r.str)==-1){var i=t.query.allFields.map(function(e){return"'"+e+"'"}).join(", "),n="unrecognised field '"+r.str+"', possible fields: "+i;throw new e.QueryParseError(n,r.start,r.end)}t.currentClause.fields=[r.str];var s=t.peekLexeme();if(void 0==s){var n="expecting term, found nothing";throw new e.QueryParseError(n,r.start,r.end)}switch(s.type){case e.QueryLexer.TERM:return e.QueryParser.parseTerm;default:var n="expecting term, found '"+s.type+"'";throw new e.QueryParseError(n,s.start,s.end)}}},e.QueryParser.parseTerm=function(t){var r=t.consumeLexeme();if(void 0!=r){t.currentClause.term=r.str.toLowerCase(),r.str.indexOf("*")!=-1&&(t.currentClause.usePipeline=!1);var i=t.peekLexeme();if(void 0==i)return void t.nextClause();switch(i.type){case e.QueryLexer.TERM:return t.nextClause(),e.QueryParser.parseTerm;case e.QueryLexer.FIELD:return t.nextClause(),e.QueryParser.parseField;case e.QueryLexer.EDIT_DISTANCE:return e.QueryParser.parseEditDistance;case e.QueryLexer.BOOST:return e.QueryParser.parseBoost;case e.QueryLexer.PRESENCE:return t.nextClause(),e.QueryParser.parsePresence;default:var n="Unexpected lexeme type '"+i.type+"'";throw new e.QueryParseError(n,i.start,i.end)}}},e.QueryParser.parseEditDistance=function(t){var r=t.consumeLexeme();if(void 0!=r){var i=parseInt(r.str,10);if(isNaN(i)){var n="edit distance must be numeric";throw new e.QueryParseError(n,r.start,r.end)}t.currentClause.editDistance=i;var s=t.peekLexeme();if(void 0==s)return void t.nextClause();switch(s.type){case e.QueryLexer.TERM:return t.nextClause(),e.QueryParser.parseTerm;case e.QueryLexer.FIELD:return t.nextClause(),e.QueryParser.parseField;case e.QueryLexer.EDIT_DISTANCE:return e.QueryParser.parseEditDistance;case e.QueryLexer.BOOST:return e.QueryParser.parseBoost;case e.QueryLexer.PRESENCE:return t.nextClause(),e.QueryParser.parsePresence;default:var n="Unexpected lexeme type '"+s.type+"'";throw new e.QueryParseError(n,s.start,s.end)}}},e.QueryParser.parseBoost=function(t){var r=t.consumeLexeme();if(void 0!=r){var i=parseInt(r.str,10);if(isNaN(i)){var n="boost must be numeric";throw new e.QueryParseError(n,r.start,r.end)}t.currentClause.boost=i;var s=t.peekLexeme();if(void 0==s)return void t.nextClause();switch(s.type){case e.QueryLexer.TERM:return t.nextClause(),e.QueryParser.parseTerm;case e.QueryLexer.FIELD:return t.nextClause(),e.QueryParser.parseField;case e.QueryLexer.EDIT_DISTANCE:return e.QueryParser.parseEditDistance;case e.QueryLexer.BOOST:return e.QueryParser.parseBoost;case e.QueryLexer.PRESENCE:return t.nextClause(),e.QueryParser.parsePresence;default:var n="Unexpected lexeme type '"+s.type+"'";throw new e.QueryParseError(n,s.start,s.end)}}},function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():e.lunr=t()}(this,function(){return e})}(); diff --git a/js/scripts.js b/js/scripts.js index c2a096022..c31e6d1df 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -120,17 +120,17 @@ function loadSearchData() { this.field('author'); this.field('category'); this.field('content'); - }); - - for (var key in searchData) { // Add the data to lunr - searchIndex.add({ - 'id': key, - 'title': searchData[key].title, - 'author': searchData[key].author, - 'category': searchData[key].category, - 'content': searchData[key].content - }); - } + + for (var key in searchData) { // Add the data to lunr + this.add({ + 'id': key, + 'title': searchData[key].title, + 'author': searchData[key].author, + 'category': searchData[key].category, + 'content': searchData[key].content + }); + } + }); } }; @@ -139,30 +139,60 @@ function loadSearchData() { }; function handleSearchInput(event) { + var searchInput = document.getElementById("search-input"); + var term = searchInput.value; + if(event.key == 'Escape') { hideSearchOverlay(); } else { if(searchDataLoading === false) { searchDataLoading = true; loadSearchData(); - } else if(searchIndex) { - var results = searchIndex.search(ref.searchInput.value); // Get lunr to perform a search - displaySearchResults(ref.searchInput.value, results); + } else if(searchIndex && term.length > 0) { + try { + // Make search fuzzy for simple terms + var adjustedTerm = term; + if(term.indexOf(' ') === -1) { + adjustedTerm = term + '~1' + } + + var results = searchIndex.search(adjustedTerm); // Get lunr to perform a search + + var highestScore, lowestScore + if(results.length > 2) { + highestScore = results[0].score; + lowestScore = results[results.length - 1].score; + + var medianScore = results[Math.round(results.length/2)].score; + var scoreSum = 0; + for(var i=0; i'; + appendString += '

' + item.title; + if(lowestScore && highestScore) { + // Calculate a color of how good of a match it is + // Green - best match + // Grey - worst match + // Result can also be somewhere in between + colorPosition = (result.score - lowestScore)/(highestScore - lowestScore) + color = { + r: Math.round(gray[0] - Math.abs(gray[0] - green[0])*colorPosition), + g: Math.round(gray[1] - Math.abs(gray[1] - green[1])*colorPosition), + b: Math.round(gray[2] - Math.abs(gray[2] - green[2])*colorPosition) + } + + if(colorPosition > 0.66) { + scoreTip = 'Great match'; + } else if(colorPosition > 0.33) { + scoreTip = 'Good match'; + } else { + scoreTip = 'OK match'; + } - appendString += '
  • '; - appendString += '

    ' + item.title + '

    '; + appendString += ''; + } + appendString += '
  • '; appendString += '

    ' + content + '...

    '; appendString += '
    '; } if(results.length > maxVisible) { - appendString += '
  • View all ' + results.length + ' results

  • '; + appendString += '
  • View all ' + results.length + ' results

  • '; } ref.searchResults.innerHTML = appendString; } else { - ref.searchResults.innerHTML = '
  • Sorry, no results...

  • '; + ref.searchResults.innerHTML = '
  • Sorry, no results...

  • '; } ref.searchResults.style.display = 'block'; @@ -313,7 +371,6 @@ function setupFeedbackModal() { var self = event.currentTarget; var container = self.parentElement; var options = container.querySelector('.next-previous--feedback__options'); - console.log('attr', options.hasAttribute('hidden')); if(options.hasAttribute('hidden')) { options.removeAttribute("hidden"); options.setAttribute("aria-expanded", true); diff --git a/js/search-page.js b/js/search-page.js index 191c4f662..0ad3a3208 100644 --- a/js/search-page.js +++ b/js/search-page.js @@ -2,6 +2,7 @@ var searchPageData = null; var searchPageDataLoading = false; var searchPageIndex = null; +var searchTipsVisible = false; function getQueryVariable(variable) { var query = window.location.search.substring(1); @@ -21,6 +22,9 @@ function loadSearchPageData() { request.onreadystatechange = function() { if (request.readyState === 4) { + var start = 578680 + var offset = 500 + var bits = request.responseText.substr(start-offset, start+offset); searchData = JSON.parse(request.responseText); searchPageIndex = lunr(function () { @@ -29,17 +33,17 @@ function loadSearchPageData() { this.field('author'); this.field('category'); this.field('content'); - }); - for (var key in searchData) { // Add the data to lunr - searchPageIndex.add({ - 'id': key, - 'title': searchData[key].title, - 'author': searchData[key].author, - 'category': searchData[key].category, - 'content': searchData[key].content - }); - } + for (var key in searchData) { // Add the data to lunr + this.add({ + 'id': key, + 'title': searchData[key].title, + 'author': searchData[key].author, + 'category': searchData[key].category, + 'content': searchData[key].content + }); + } + }); var searchInput = document.getElementById("search-page-input"); var searchTerm = searchInput.value; @@ -59,22 +63,55 @@ function handleSearchPageInput() { if(searchPageDataLoading === false) { searchPageDataLoading = true; loadSearchPageData(); - } else if(searchPageIndex) { - var results = searchPageIndex.search(searchInput.value); // Get lunr to perform a search - displaySearchPageResults(searchInput, results); + } else if(searchPageIndex && searchInput.value.length > 0) { + var term = searchInput.value; + + // Make search fuzzy for simple terms + if(term.indexOf(' ') === -1) { + term = term + '~1' + } + + // Get lunr to perform a search + try { + var results = searchPageIndex.search(term); + + var highestScore, lowestScore + if(results.length > 2) { + highestScore = results[0].score; + lowestScore = results[results.length - 1].score; + + var medianScore = results[Math.round(results.length/2)].score; + var scoreSum = 0; + for(var i=0; i'; - appendString += '

    ' + item.title + '

    '; + // Content includes the page title at the start. Remove it. + if(content.indexOf(item.title) === 0) { + content = content.substr(item.title.length) + } + + appendString += '
  • '; + appendString += '

    ' + item.title; + if(lowestScore && highestScore) { + // Calculate a color of how good of a match it is + // Green - best match + // Grey - worst match + // Result can also be somewhere in between + colorPosition = (result.score - lowestScore)/(highestScore - lowestScore) + color = { + r: Math.round(gray[0] - Math.abs(gray[0] - green[0])*colorPosition), + g: Math.round(gray[1] - Math.abs(gray[1] - green[1])*colorPosition), + b: Math.round(gray[2] - Math.abs(gray[2] - green[2])*colorPosition) + } + + if(colorPosition > 0.66) { + scoreTip = 'Great match'; + } else if(colorPosition > 0.33) { + scoreTip = 'Good match'; + } else { + scoreTip = 'OK match'; + } + + appendString += ''; + } + appendString += '

    '; appendString += '

    ' + content + '...

    '; appendString += '
  • '; } searchResults.innerHTML = appendString; } else { - searchResults.innerHTML = '
  • Sorry, no results...

  • '; + searchResults.innerHTML = '
  • Sorry, no results...

  • '; } searchResults.style.display = 'block'; } +function toggleSearchTips() { + searchTipsVisible = !searchTipsVisible; + var searchTips = document.getElementById('search-tips'); + var searchTipsContent = document.getElementById('search-tips-content'); + var searchTipsButton = searchTips.getElementsByTagName('button')[0]; + + searchTipsButton.setAttribute('aria-expanded', searchTipsVisible); + + if(searchTipsVisible) { + searchTipsContent.removeAttribute('hidden'); + } else { + searchTipsContent.setAttribute('hidden', true); + } +} + document.addEventListener("DOMContentLoaded", function(event) { var searchInput = document.getElementById("search-page-input"); @@ -113,4 +193,8 @@ document.addEventListener("DOMContentLoaded", function(event) { loadSearchPageData(); } } -}); \ No newline at end of file + + var searchTips = document.getElementById('search-tips'); + var searchTipsButton = searchTips.getElementsByTagName('button')[0]; + searchTipsButton.addEventListener('click', toggleSearchTips); +}); diff --git a/search-data.json b/search-data.json index 87d3df0fd..bfd7d6f30 100644 --- a/search-data.json +++ b/search-data.json @@ -4,15 +4,20 @@ layout: null { {%- assign content_pages = site.html_pages -%} {%- assign content = site.posts | concat: content_pages -%} + {% assign counter = 0 %} {% for page in content %} - "{{ page.url }}": { - "title": "{{ page.title | xml_escape }}", - "author": "{{ page.author | xml_escape }}", - "category": "{{ page.category | xml_escape }}", - "content": {{ page.content | markdownify | strip_html | strip_newlines | jsonify }}, - "url": "{{ page.url | relative_url | xml_escape }}" - } - {% unless forloop.last %},{% endunless %} + {% assign titleLength = page.title.size %} + {% if titleLength > 3 and page.exclude_from_search != true %} + {% if counter > 0 %},{% endif %} + "{{ page.url }}": { + "title": "{{ page.title | xml_escape }}", + "author": "{{ page.author | xml_escape }}", + "category": "{{ page.category | xml_escape }}", + "content": {{ page.content | markdownify | strip_html | strip_newlines | jsonify }}, + "url": "{{ page.url | relative_url | xml_escape }}" + } + {% assign counter = counter | plus:1 %} + {% endif %} {% endfor %} } diff --git a/search.html b/search.html index ade4df0fa..d9499ee26 100644 --- a/search.html +++ b/search.html @@ -3,32 +3,55 @@ description: Search the Bitcoin Design Guide layout: search image: /assets/images/search-preview.jpg +exclude_from_search: true --- -
    - + +
      +
      + + +
      +