diff options
| author | Jieiku | 2022-05-30 22:38:50 -0700 |
|---|---|---|
| committer | Jieiku | 2022-05-30 22:38:50 -0700 |
| commit | 03f402c3e4fe8865571cf462e60dec5e0c9b713a (patch) | |
| tree | 7beb2a634bc4a3ebfdfa20bacdba8fa663b591cb | |
| parent | 9c1f02f9099b0da48c0bec7f23fa8c0566a331f3 (diff) | |
| download | abridge-03f402c3e4fe8865571cf462e60dec5e0c9b713a.tar.gz abridge-03f402c3e4fe8865571cf462e60dec5e0c9b713a.tar.bz2 abridge-03f402c3e4fe8865571cf462e60dec5e0c9b713a.zip | |
Add Search and Improve Contrast
| -rw-r--r-- | README.md | 14 | ||||
| -rw-r--r-- | config.toml | 2 | ||||
| -rw-r--r-- | content/pages/about.md | 2 | ||||
| -rw-r--r-- | sass/_variables.scss | 4 | ||||
| -rw-r--r-- | sass/abridge.scss | 2 | ||||
| -rw-r--r-- | sass/include/_nav.scss | 26 | ||||
| -rw-r--r-- | sass/include/_recent.scss | 35 | ||||
| -rw-r--r-- | sass/include/_search.scss | 46 | ||||
| -rw-r--r-- | sass/themes/_auto.scss | 10 | ||||
| -rw-r--r-- | sass/themes/_light.scss | 6 | ||||
| -rw-r--r-- | screenshot.png | bin | 188541 -> 190381 bytes | |||
| -rw-r--r-- | static/processed_images/199de027950a8f4800.jpg | bin | 0 -> 37494 bytes | |||
| -rw-r--r-- | static/search.min.js | 1 | ||||
| -rw-r--r-- | templates/base.html | 36 | ||||
| -rw-r--r-- | templates/index.html | 2 |
15 files changed, 121 insertions, 65 deletions
@@ -2,6 +2,8 @@ Abridge is a fast and lightweight Zola theme using semantic html, class-light [abridge.css](https://github.com/jieiku/abridge.css), and No JS. + + ## Demo [https://jieiku.github.io/abridge-demo/](https://jieiku.github.io/abridge-demo/) @@ -117,10 +119,11 @@ Use search function for the content. build_search_index = true ``` -Currently this theme has not yet implemented a search, there are however several themes that have. -For the moment you can look at how those other themes have implemented their search. -I plan to implement a search field eventually, but am still weighing my options. -I would prefer a self hosted search method that works even if javascript is disabled in the browser. (open an issue report if you know of one.) +The search is the only thing that requires javascript in this this theme. + +If you set `build_search_index` to false then the javascript file will no longer be loaded. + +The default elasticlunr search is currently used, I may eventually switch this out for something else. #### Configuration options under the `extra` @@ -204,8 +207,7 @@ If your problem or idea is not addressed yet, [open a new issue](https://github. ## Contributing We'd love your help! Especially with fixes to issues. -The overall idea behind abridge is to be lightweight and fast, and to use zero javascript. -The only place that I may eventually add javascript will be for the site search, but hopefully I can find another way. +The overall idea behind abridge is to be lightweight and fast, and to use zero javascript other than the search. ## License diff --git a/config.toml b/config.toml index 7cb9809..6e6b5cc 100644 --- a/config.toml +++ b/config.toml @@ -6,7 +6,7 @@ default_language = "en" output_dir = "public" compile_sass = true -build_search_index = false +build_search_index = true minify_html = false generate_feed = true feed_filename = "atom.xml" diff --git a/content/pages/about.md b/content/pages/about.md index 1e7d7e7..6632426 100644 --- a/content/pages/about.md +++ b/content/pages/about.md @@ -12,7 +12,7 @@ Some fun facts about the theme: * Perfect score on Google's Lighthouse audit * Only ~4 KB of CSS before enabling the SVG CSS icons. -* No JavaScript +* No JavaScript (except the search which can be disabled) * Now with SEO! Nearly half of the existing Zola MIT themes were inspiration for features and design of this theme. diff --git a/sass/_variables.scss b/sass/_variables.scss index 72adc3e..6fa3915 100644 --- a/sass/_variables.scss +++ b/sass/_variables.scss @@ -15,8 +15,8 @@ $enable-responsive-spacings: false !default; // Enable a centered viewport for <header>, <main>, <footer> inside <body> // Fluid layout until it reaches a defined size, then becomes a centered viewport $enable-maxwidth: true !default; -$mw:60% !default;// max-width -$mb:1200px !default;// value at which to switch from fluid layout to using max-width +$mw:50% !default;// max-width +$mb:1000px !default;// value at which to switch from fluid layout to using max-width // Enable a centered viewport for <header>, <main>, <footer> inside <body> // This option will only work if $enable-maxwidth: false diff --git a/sass/abridge.scss b/sass/abridge.scss index d69bd5d..6b8733a 100644 --- a/sass/abridge.scss +++ b/sass/abridge.scss @@ -31,6 +31,8 @@ @import "include/code"; // pre, code, ... @import "include/hr"; // hr +@import "include/search"; // Zola Search - elasticlunr site-wide search + @import "include/toc"; // Zola TOC - Table of Content Menu (recent posts & index), sticky (floats top right) //@import "include/scroller"; // figure diff --git a/sass/include/_nav.scss b/sass/include/_nav.scss index 543d88c..a1e5402 100644 --- a/sass/include/_nav.scss +++ b/sass/include/_nav.scss @@ -13,19 +13,21 @@ main nav a:visited { main nav a:hover { border-color: var(--a3); } +nav > div:first-of-type { + margin-left: auto +} +nav > div { + ul { + line-height: 0; + margin-top: 0; + padding-bottom: var(--s1); + } + display: block; + margin-left: var(--s1); +} nav { align-items: center; display: flex; - justify-content: space-between; - div { - ul { - line-height: 0; - margin-top: 0; - padding-bottom: var(--s1); - } - display: block; - margin-left: auto - } div h2 { font-size: 1rem; &:hover { @@ -44,6 +46,10 @@ nav { position: relative; text-align: left; } + div div { + display: inline-block; + position: relative; + } } @if map-get($breakpoints, "md") { diff --git a/sass/include/_recent.scss b/sass/include/_recent.scss deleted file mode 100644 index 88b5763..0000000 --- a/sass/include/_recent.scss +++ /dev/null @@ -1,35 +0,0 @@ -main { - .toc { - max-width: 260px; - min-width: 240px; - } - .toc-item { - padding: 10px 20px; - color: var(--f1); - } - .toc-item a, .toc-item-child a { - color: var(--f1); - &:hover { - cursor: pointer; - color: var(--a2); - text-decoration: underline; - } - } - .toc-item a.active, .toc-item-child a.active { - color: var(--a2); - } - .toc-item-child { - padding: 0 30px 5px; - color: var(--f1); - } -} -.toc-sticky { - border-radius: var(--br); - border-top: 5px solid var(--a1); - background-color: var(--c2); - position: sticky; - top: 10px; - padding: 10px 0 20px; - max-height: 100vh; - overflow: auto; -} diff --git a/sass/include/_search.scss b/sass/include/_search.scss new file mode 100644 index 0000000..82c06fa --- /dev/null +++ b/sass/include/_search.scss @@ -0,0 +1,46 @@ +div:empty { + display: none; +} +#suggestions { + z-index: 9; + background: var(--c1); + border: 2px solid var(--c3); + position: absolute; + right: 0; + margin-top: var(--s1); + width: 500px; + max-height: 500px; + overflow: auto; +} +#suggestions a { + display: block; + text-decoration: none; + padding: var(--s1); + margin: 0 var(--s1); +} +#suggestions a:hover, +#suggestions a:focus { + background: var(--c2); +} +#suggestions span { + line-height: 1.5; + display: block; +} +#suggestions span:first-child { + font-weight: var(--fh); +} +#suggestions span:nth-child(2) { + color: var(--f1); +} +@if map-get($breakpoints, "md") { + @media (max-width: map-get($breakpoints, "md")) { + nav div:last-of-type, input { + width: 100%; + } + #suggestions { + position: static; + left: 0; + width: 100%; + } + } +} diff --git a/sass/themes/_auto.scss b/sass/themes/_auto.scss index 012aa9b..0c59f07 100644 --- a/sass/themes/_auto.scss +++ b/sass/themes/_auto.scss @@ -17,9 +17,9 @@ --c3: #ddd; //color 3 333 --c4: #777; //color 4 888 - --a1: #f90; //accent color 1 link - --a2: #fb0; //accent color 2 hover,focus - --a3: #fb0; //accent color 3 h1-h2 hover,focus + --a1: #c40; //accent color 1 link + --a2: #e60; //accent color 2 hover,focus + --a3: #e60; //accent color 3 h1-h2 hover,focus --cg: #483; //ins green --cr: #d33; //del red @@ -67,6 +67,10 @@ --c2: #222; //color 2 --c3: #333; //color 3 --c4: #888; //color 4 + + --a1: #f90; //accent color 1 link + --a2: #fb0; //accent color 2 hover,focus + --a3: #fb0; //accent color 3 h1-h2 hover,focus } } diff --git a/sass/themes/_light.scss b/sass/themes/_light.scss index 127073c..1848f4e 100644 --- a/sass/themes/_light.scss +++ b/sass/themes/_light.scss @@ -17,9 +17,9 @@ --c3: #ddd; //color 3 333 --c4: #777; //color 4 888 - --a1: #f90; //accent color 1 link - --a2: #fb0; //accent color 2 hover,focus - --a3: #fb0; //accent color 3 h1-h2 hover,focus + --a1: #c40; //accent color 1 link + --a2: #e60; //accent color 2 hover,focus + --a3: #e60; //accent color 3 h1-h2 hover,focus --cg: #483; //ins green --cr: #d33; //del red diff --git a/screenshot.png b/screenshot.png Binary files differindex 109c038..55bd732 100644 --- a/screenshot.png +++ b/screenshot.png diff --git a/static/processed_images/199de027950a8f4800.jpg b/static/processed_images/199de027950a8f4800.jpg Binary files differnew file mode 100644 index 0000000..51d50a8 --- /dev/null +++ b/static/processed_images/199de027950a8f4800.jpg diff --git a/static/search.min.js b/static/search.min.js new file mode 100644 index 0000000..a37a809 --- /dev/null +++ b/static/search.min.js @@ -0,0 +1 @@ +!function(){function y(e){var t=new y.Index;return t.pipeline.add(y.trimmer,y.stopWordFilter,y.stemmer),e&&e.call(t,t),t}var a,c,e,t,d,h,f,p,g,v,m,S,x,w,b,I,E,D,F,k,_,C,P,N,n;y.version="0.9.5",((lunr=y).utils={}).warn=(n=this,function(e){n.console&&console.warn&&console.warn(e)}),y.utils.toString=function(e){return null==e?"":e.toString()},(y.EventEmitter=function(){this.events={}}).prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop();if("function"!=typeof t)throw new TypeError("last argument must be a function");e.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},y.EventEmitter.prototype.removeListener=function(e,t){this.hasHandler(e)&&-1!==(t=this.events[e].indexOf(t))&&(this.events[e].splice(t,1),0==this.events[e].length&&delete this.events[e])},y.EventEmitter.prototype.emit=function(e){var t;this.hasHandler(e)&&(t=Array.prototype.slice.call(arguments,1),this.events[e].forEach(function(e){e.apply(void 0,t)},this))},y.EventEmitter.prototype.hasHandler=function(e){return e in this.events},(y.tokenizer=function(e){return arguments.length&&null!=e?Array.isArray(e)?(t=(t=e.filter(function(e){return null!=e})).map(function(e){return y.utils.toString(e).toLowerCase()}),n=[],t.forEach(function(e){e=e.split(y.tokenizer.seperator);n=n.concat(e)},this),n):e.toString().trim().toLowerCase().split(y.tokenizer.seperator):[];var t,n}).defaultSeperator=/[\s\-]+/,y.tokenizer.seperator=y.tokenizer.defaultSeperator,y.tokenizer.setSeperator=function(e){null!=e&&"object"==typeof e&&(y.tokenizer.seperator=e)},y.tokenizer.resetSeperator=function(){y.tokenizer.seperator=y.tokenizer.defaultSeperator},y.tokenizer.getSeperator=function(){return y.tokenizer.seperator},(y.Pipeline=function(){this._queue=[]}).registeredFunctions={},y.Pipeline.registerFunction=function(e,t){t in y.Pipeline.registeredFunctions&&y.utils.warn("Overwriting existing registered function: "+t),e.label=t,y.Pipeline.registeredFunctions[t]=e},y.Pipeline.getRegisteredFunction=function(e){return e in y.Pipeline.registeredFunctions!=1?null:y.Pipeline.registeredFunctions[e]},y.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions||y.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},y.Pipeline.load=function(e){var n=new y.Pipeline;return e.forEach(function(e){var t=y.Pipeline.getRegisteredFunction(e);if(!t)throw new Error("Cannot load un-registered function: "+e);n.add(t)}),n},y.Pipeline.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(e){y.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},y.Pipeline.prototype.after=function(e,t){y.Pipeline.warnIfFunctionNotRegistered(t);e=this._queue.indexOf(e);if(-1===e)throw new Error("Cannot find existingFn");this._queue.splice(e+1,0,t)},y.Pipeline.prototype.before=function(e,t){y.Pipeline.warnIfFunctionNotRegistered(t);e=this._queue.indexOf(e);if(-1===e)throw new Error("Cannot find existingFn");this._queue.splice(e,0,t)},y.Pipeline.prototype.remove=function(e){e=this._queue.indexOf(e);-1!==e&&this._queue.splice(e,1)},y.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,o=this._queue.length,i=0;i<n;i++){for(var r=e[i],s=0;s<o&&null!=(r=this._queue[s](r,i,e));s++);null!=r&&t.push(r)}return t},y.Pipeline.prototype.reset=function(){this._queue=[]},y.Pipeline.prototype.get=function(){return this._queue},y.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return y.Pipeline.warnIfFunctionNotRegistered(e),e.label})},(y.Index=function(){this._fields=[],this._ref="id",this.pipeline=new y.Pipeline,this.documentStore=new y.DocumentStore,this.index={},this.eventEmitter=new y.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))}).prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},y.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},y.Index.load=function(e){e.version!==y.version&&y.utils.warn("version mismatch: current "+y.version+" importing "+e.version);var t,n=new this;for(t in n._fields=e.fields,n._ref=e.ref,n.documentStore=y.DocumentStore.load(e.documentStore),n.pipeline=y.Pipeline.load(e.pipeline),n.index={},e.index)n.index[t]=y.InvertedIndex.load(e.index[t]);return n},y.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new y.InvertedIndex,this},y.Index.prototype.setRef=function(e){return this._ref=e,this},y.Index.prototype.saveDocument=function(e){return this.documentStore=new y.DocumentStore(e),this},y.Index.prototype.addDoc=function(r,e){var s;r&&(e=void 0===e||e,s=r[this._ref],this.documentStore.addDoc(s,r),this._fields.forEach(function(e){var t,n=this.pipeline.run(y.tokenizer(r[e])),o=(this.documentStore.addFieldLength(s,e,n.length),{});for(t in n.forEach(function(e){e in o?o[e]+=1:o[e]=1},this),o){var i=o[t],i=Math.sqrt(i);this.index[e].addToken(t,{ref:s,tf:i})}},this),e&&this.eventEmitter.emit("add",r,this))},y.Index.prototype.removeDocByRef=function(e){e&&!1!==this.documentStore.isDocStored()&&this.documentStore.hasDoc(e)&&(e=this.documentStore.getDoc(e),this.removeDoc(e,!1))},y.Index.prototype.removeDoc=function(e,t){var n;e&&(t=void 0===t||t,n=e[this._ref],this.documentStore.hasDoc(n)&&(this.documentStore.removeDoc(n),this._fields.forEach(function(t){this.pipeline.run(y.tokenizer(e[t])).forEach(function(e){this.index[t].removeToken(e,n)},this)},this),t&&this.eventEmitter.emit("remove",e,this)))},y.Index.prototype.updateDoc=function(e,t){t=void 0===t||t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},y.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,n))return this._idfCache[n];t=this.index[t].getDocFreq(e),e=1+Math.log(this.documentStore.length/(t+1));return this._idfCache[n]=e},y.Index.prototype.getFields=function(){return this._fields.slice()},y.Index.prototype.search=function(e,t){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var n=null;null!=t&&(n=JSON.stringify(t));for(var o=new y.Configuration(n,this.getFields()).get(),i={},r=Object.keys(e),s=0;s<r.length;s++){var u=r[s];i[u]=this.pipeline.run(y.tokenizer(e[u]))}var l,a={};for(l in o){var c=i[l]||i.any;if(c){var d=this.fieldSearch(c,l,o),h=o[l].boost;for(p in d)d[p]=d[p]*h;for(p in d)p in a?a[p]+=d[p]:a[p]=d[p]}}var f,p,g=[];for(p in a)f={ref:p,score:a[p]},this.documentStore.hasDoc(p)&&(f.doc=this.documentStore.getDoc(p)),g.push(f);return g.sort(function(e,t){return t.score-e.score}),g},y.Index.prototype.fieldSearch=function(e,d,t){var h=t[d].bool,n=t[d].expand,t=t[d].boost,f=null,p={};return 0!==t?(e.forEach(function(a){var e=[a],c=(1==n&&(e=this.index[d].expandToken(a)),{});e.forEach(function(e){var t=this.index[d].getDocs(e),n=this.idf(e,d);if(f&&"AND"==h){var o,i={};for(o in f)o in t&&(i[o]=t[o]);t=i}for(o in e==a&&this.fieldSearchStats(p,e,t),t){var r=this.index[d].getTermFrequency(e,o),s=this.documentStore.getFieldLength(o,d),u=1,l=1,r=r*n*(u=0!=s?1/Math.sqrt(s):u)*(l=e!=a?.15*(1-(e.length-a.length)/e.length):l);o in c?c[o]+=r:c[o]=r}},this),f=this.mergeScores(f,c,h)},this),f=this.coordNorm(f,p,e.length)):void 0},y.Index.prototype.mergeScores=function(e,t,n){if(!e)return t;if("AND"==n){var o={};for(i in t)i in e&&(o[i]=e[i]+t[i]);return o}for(var i in t)i in e?e[i]+=t[i]:e[i]=t[i];return e},y.Index.prototype.fieldSearchStats=function(e,t,n){for(var o in n)o in e?e[o].push(t):e[o]=[t]},y.Index.prototype.coordNorm=function(e,t,n){for(var o in e){var i;o in t&&(i=t[o].length,e[o]=e[o]*i/n)}return e},y.Index.prototype.toJSON=function(){var t={};return this._fields.forEach(function(e){t[e]=this.index[e].toJSON()},this),{version:y.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),index:t,pipeline:this.pipeline.toJSON()}},y.Index.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},(y.DocumentStore=function(e){this._save=null==e||e,this.docs={},this.docInfo={},this.length=0}).load=function(e){var t=new this;return t.length=e.length,t.docs=e.docs,t.docInfo=e.docInfo,t._save=e.save,t},y.DocumentStore.prototype.isDocStored=function(){return this._save},y.DocumentStore.prototype.addDoc=function(e,t){this.hasDoc(e)||this.length++,this.docs[e]=!0===this._save?function(e){if(null===e||"object"!=typeof e)return e;var t,n=e.constructor();for(t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);return n}(t):null},y.DocumentStore.prototype.getDoc=function(e){return!1===this.hasDoc(e)?null:this.docs[e]},y.DocumentStore.prototype.hasDoc=function(e){return e in this.docs},y.DocumentStore.prototype.removeDoc=function(e){this.hasDoc(e)&&(delete this.docs[e],delete this.docInfo[e],this.length--)},y.DocumentStore.prototype.addFieldLength=function(e,t,n){null!=e&&0!=this.hasDoc(e)&&(this.docInfo[e]||(this.docInfo[e]={}),this.docInfo[e][t]=n)},y.DocumentStore.prototype.updateFieldLength=function(e,t,n){null!=e&&0!=this.hasDoc(e)&&this.addFieldLength(e,t,n)},y.DocumentStore.prototype.getFieldLength=function(e,t){return null!=e&&e in this.docs&&t in this.docInfo[e]?this.docInfo[e][t]:0},y.DocumentStore.prototype.toJSON=function(){return{docs:this.docs,docInfo:this.docInfo,length:this.length,save:this._save}},a={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"},c={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},e="[aeiouy]",t="[^aeiou][^aeiouy]*",d=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),h=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),f=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$"),p=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy]"),g=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,m=/^(.+?)eed$/,S=/^(.+?)(ed|ing)$/,x=/.$/,w=/(at|bl|iz)$/,b=new RegExp("([^aeiouylsz])\\1$"),I=new RegExp("^"+t+e+"[^aeiouwxy]$"),E=/^(.+?[^aeiou])y$/,D=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,F=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,k=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,_=/^(.+?)(s|t)(ion)$/,C=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+t+e+"[^aeiouwxy]$"),y.Pipeline.registerFunction(y.stemmer=function(e){var t,n,o,i,r,s,u,l;return e.length<3?e:("y"==(n=e.substr(0,1))&&(e=n.toUpperCase()+e.substr(1)),u=v,(r=g).test(e)?e=e.replace(r,"$1$2"):u.test(e)&&(e=e.replace(u,"$1$2")),u=S,(r=m).test(e)?(l=r.exec(e),(r=d).test(l[1])&&(e=e.replace(r=x,""))):u.test(e)&&(s=(l=u.exec(e))[1],(u=p).test(s)&&(e=s,o=b,i=I,(u=w).test(e)?e+="e":o.test(e)?e=e.replace(r=x,""):i.test(e)&&(e+="e"))),(r=E).test(e)&&(e=(s=(l=r.exec(e))[1])+"i"),(r=D).test(e)&&(s=(l=r.exec(e))[1],t=l[2],(r=d).test(s)&&(e=s+a[t])),(r=F).test(e)&&(s=(l=r.exec(e))[1],t=l[2],(r=d).test(s)&&(e=s+c[t])),u=_,(r=k).test(e)?(s=(l=r.exec(e))[1],(r=h).test(s)&&(e=s)):u.test(e)&&(s=(l=u.exec(e))[1]+l[2],(u=h).test(s)&&(e=s)),(r=C).test(e)&&(s=(l=r.exec(e))[1],u=f,o=N,((r=h).test(s)||u.test(s)&&!o.test(s))&&(e=s)),u=h,(r=P).test(e)&&u.test(e)&&(e=e.replace(r=x,"")),"y"==n?n.toLowerCase()+e.substr(1):e)},"stemmer"),y.stopWordFilter=function(e){return e&&!0!==y.stopWordFilter.stopWords[e]?e:void 0},y.clearStopWords=function(){y.stopWordFilter.stopWords={}},y.addStopWords=function(e){null!=e&&!1!==Array.isArray(e)&&e.forEach(function(e){y.stopWordFilter.stopWords[e]=!0},this)},y.resetStopWords=function(){y.stopWordFilter.stopWords=y.defaultStopWords},y.stopWordFilter.stopWords=y.defaultStopWords={"":!0,a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,do:!0,does:!0,either:!0,else:!0,ever:!0,every:!0,for:!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,if:!0,in:!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,this:!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,while:!0,who:!0,whom:!0,why:!0,will:!0,with:!0,would:!0,yet:!0,you:!0,your:!0},y.Pipeline.registerFunction(y.stopWordFilter,"stopWordFilter"),y.Pipeline.registerFunction(y.trimmer=function(e){if(null==e)throw new Error("token should not be undefined");return e.replace(/^\W+/,"").replace(/\W+$/,"")},"trimmer"),(y.InvertedIndex=function(){this.root={docs:{},df:0}}).load=function(e){var t=new this;return t.root=e.root,t},y.InvertedIndex.prototype.addToken=function(e,t,n){for(var n=n||this.root,o=0;o<=e.length-1;){var i=e[o];i in n||(n[i]={docs:{},df:0}),o+=1,n=n[i]}var r=t.ref;n.docs[r]?n.docs[r]={tf:t.tf}:(n.docs[r]={tf:t.tf},n.df+=1)},y.InvertedIndex.prototype.hasToken=function(e){if(!e)return!1;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return!1;t=t[e[n]]}return!0},y.InvertedIndex.prototype.getNode=function(e){if(!e)return null;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return null;t=t[e[n]]}return t},y.InvertedIndex.prototype.getDocs=function(e){e=this.getNode(e);return null==e?{}:e.docs},y.InvertedIndex.prototype.getTermFrequency=function(e,t){e=this.getNode(e);return null!=e&&t in e.docs?e.docs[t].tf:0},y.InvertedIndex.prototype.getDocFreq=function(e){e=this.getNode(e);return null==e?0:e.df},y.InvertedIndex.prototype.removeToken=function(e,t){e&&null!=(e=this.getNode(e))&&t in e.docs&&(delete e.docs[t],--e.df)},y.InvertedIndex.prototype.expandToken=function(e,t,n){if(null==e||""==e)return[];var o,t=t||[];if(null==n&&null==(n=this.getNode(e)))return t;for(o in 0<n.df&&t.push(e),n)"docs"!==o&&"df"!==o&&this.expandToken(e+o,t,n[o]);return t},y.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},(y.Configuration=function(e,t){var n,e=e||"";if(null==t)throw new Error("fields should not be null");this.config={};try{n=JSON.parse(e),this.buildUserConfig(n,t)}catch(e){y.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(t)}}).prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},y.Configuration.prototype.buildUserConfig=function(e,t){var n,o,i="OR",r=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(r=e.expand||r),"fields"in e)for(var s in e.fields)-1<t.indexOf(s)?(o=r,null!=(n=e.fields[s]).expand&&(o=n.expand),this.config[s]={boost:n.boost||0===n.boost?n.boost:1,bool:n.bool||i,expand:o}):y.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,r,t)},y.Configuration.prototype.addAllFields2UserConfig=function(t,n,e){e.forEach(function(e){this.config[e]={boost:1,bool:t,expand:n}},this)},y.Configuration.prototype.get=function(){return this.config},y.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){for(var e,t=0;t<arguments.length;t++)~this.indexOf(e=arguments[t])||this.elements.splice(this.locationFor(e),0,e);this.length=this.elements.length},lunr.SortedSet.prototype.toArray=function(){return this.elements.slice()},lunr.SortedSet.prototype.map=function(e,t){return this.elements.map(e,t)},lunr.SortedSet.prototype.forEach=function(e,t){return this.elements.forEach(e,t)},lunr.SortedSet.prototype.indexOf=function(e){for(var t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];1<o;){if(r===e)return i;o=(n=e<r?i:n)-(t=r<e?i:t),i=t+Math.floor(o/2),r=this.elements[i]}return r===e?i:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];1<o;)o=(n=e<r?i:n)-(t=r<e?i:t),i=t+Math.floor(o/2),r=this.elements[i];return e<r?i:r<e?i+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,o=0,i=this.length,r=e.length,s=this.elements,u=e.elements;!(i-1<n||r-1<o);)s[n]!==u[o]?s[n]<u[o]?n++:s[n]>u[o]&&o++:(t.add(s[n]),n++,o++);return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){for(var t,e=this.length>=e.length?(t=this,e):(t=e,this),n=t.clone(),o=0,i=e.toArray();o<i.length;o++)n.add(i[o]);return n},lunr.SortedSet.prototype.toJSON=function(){return this.toArray()},t=this,e=function(){return y},"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=y:t.elasticlunr=y}();var suggestions=document.getElementById("suggestions"),userinput=document.getElementById("userinput");function inputFocus(e){191===e.keyCode&&(e.preventDefault(),userinput.focus()),27===e.keyCode&&(userinput.blur(),suggestions.classList.add("d-none"))}function suggestionFocus(e){const t=suggestions.querySelectorAll("a"),n=[...t],o=n.indexOf(document.activeElement);let i=0;38===e.keyCode?(e.preventDefault(),t[i=0<o?o-1:0].focus()):40===e.keyCode&&(e.preventDefault(),t[i=o+1<n.length?o+1:o].focus())}function substringByByte(e,t){for(var n="",o=!1,i=0,r=0,s=0,u=0;u<e.length;u++){var l=e.codePointAt(u).toString(16);if(o=4<l.length&&++u+1<e.length?"200d"==e.codePointAt(u+1).toString(16):o){if(i+=getByteByHex(l),u==e.length-1){if(!((r+=i)<=t))break;n+=e.substr(s,u-s+1)}}else if(0!=i){if(!((r=(r+=i)+getByteByHex(l))<=t))break;n+=e.substr(s,u-s+1),s=u+1,i=0}else{if(!((r+=getByteByHex(l))<=t))break;l.length<=4?n+=e[u]:n+=e[u-1]+e[u],s=u+1}}return n}function getByteByBinary(e){return[0,1,2,3,4][Math.ceil(e.length/8)]}function getByteByHex(e){return getByteByBinary(parseInt(e,16).toString(2))}document.addEventListener("keydown",inputFocus),document.addEventListener("click",function(e){suggestions.contains(e.target)||suggestions.classList.add("d-none")}),document.addEventListener("keydown",suggestionFocus),function(){var s=elasticlunr.Index.load(window.searchIndex);userinput.addEventListener("input",function(){var n,e=this.value.trim(),o=s.search(e,{bool:"OR",fields:{title:{boost:2},body:{boost:1}}}),i=suggestions.childNodes,r=o.length,x=e.split(/\s+/);for(suggestions.classList.remove("d-none"),o.forEach(function(e){""!==e.doc.body&&((n=document.createElement("div")).innerHTML="<a href><span></span><span></span></a>",a=n.querySelector("a"),t=n.querySelector("span:first-child"),d=n.querySelector("span:nth-child(2)"),a.href=e.ref,t.textContent=e.doc.title,d.innerHTML=function(e){var t=x.map(function(e){return elasticlunr.stemmer(e.toLowerCase())}),n=!1,o=0,i=[],r=e.toLowerCase().split(". ");for(g in r){var s,u=r[g].split(/[\s\n]/),l=8;for(s in u){if(0<(y=u[s]).length){for(var a in t)elasticlunr.stemmer(y).startsWith(t[a])&&(l=40,n=!0);i.push([y,l,o]),l=2}o=o+y.length+1}o+=1}if(0===i.length)return void 0!==e.length&&300<e.length?e.substring(0,300)+"...":e;var c=[],d=Math.min(i.length,30),h=0;for(g=0;g<d;g++)h+=i[g][1];for(c.push(h),g=0;g<i.length-d;g++)h=(h-=i[g][1])+i[g+d][1],c.push(h);var f=0;if(n)for(var p=0,g=c.length-1;0<=g;g--)c[g]>p&&(p=c[g],f=g);var y,v,m=[],S=i[f][2];for(g=f;g<f+d;g++)S<(y=i[g])[2]&&(m.push(e.substring(S,y[2])),S=y[2]),40===y[1]&&m.push("<b>"),S=y[2]+y[0].length,40!==y[1]&&12<=y[0].length&&!/^[\x00-\xff]+$/.test(y[0])?(v=substringByByte(e.substring(y[2],S),12),m.push(v)):m.push(e.substring(y[2],S)),40===y[1]&&m.push("</b>");return m.push("…"),m.join("")}(e.doc.body),suggestions.appendChild(n))});i.length>r;)suggestions.removeChild(i[0])},!0),suggestions.addEventListener("click",function(){for(;suggestions.lastChild;)suggestions.removeChild(suggestions.lastChild);return!1},!0)}();
\ No newline at end of file diff --git a/templates/base.html b/templates/base.html index f43dcba..18e1fb4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,6 +8,24 @@ {% block title %}<title>{% if page.title %}{{ page.title }} | {% endif %}{{ config.title }}</title>{% endblock title %} + {% if is_404 %} + <meta name="robots" content="noindex, follow"> + {% else %} + <meta name="robots" content="index, follow"> + <meta name="googlebot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"> + <meta name="bingbot" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1"> + {% endif %} + {% if current_url %} + {% set page_url = current_url %} + {% else %} + {% set page_url = get_url(path="404.html") %} + {% endif %} + {% if current_path %} + {% set page_path = current_path %} + {% else %} + {% set page_path = "/404.html" %} + {% endif %} + {% block description %} {% if page.description %} <meta name="description" content="{{ page.description }}" /> @@ -40,8 +58,7 @@ {% if config.extra.google %}<meta name="google-site-verification" content="{{ config.extra.google | safe }}">{% endif %} {% if config.extra.bing %}<meta name="msvalidate.01" content="{{ config.extra.bing | safe}}">{% endif %} <meta name="referrer" content="no-referrer-when-downgrade"> - <meta name="robots" content="index, follow"> - <meta name="googlebot" content="index,follow"> + <meta name="HandheldFriendly" content="True"> <meta name="mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes"> @@ -109,6 +126,11 @@ {% endif %} {% endif %} + {% if config.build_search_index %} + <script type="text/javascript" src="{{ get_url(path="search_index.en.js", trailing_slash=false, cachebust=true) | safe }}" defer></script> + <script type="text/javascript" src="{{ get_url(path="search.min.js", trailing_slash=false, cachebust=true) | safe }}" defer></script> + {% endif %} + {% block extra_head %}{% endblock extra_head %} </head> <body> @@ -118,11 +140,19 @@ <header> <h1><a href="{{ get_url(path="/", trailing_slash=true) }}">{{ config.extra.textlogo | safe }}</a></h1> </header> - <div overflow> + <div> <ul> {% for i in config.extra.menu %}<li><h2><a href="{{ get_url(path=i.url, trailing_slash=i.slash) }}">{{ i.name }}</a></h2></li>{% endfor %} </ul> </div> + {% if config.build_search_index %} + <div> + <form> + <input id="userinput" type="search" placeholder="Search" autocomplete="off"> + <div><div id="suggestions"></div></div> + </form> + </div> + {% endif %} </nav> {% if config.extra.sitedesc %} {% if config.description %} diff --git a/templates/index.html b/templates/index.html index ad4af41..79e187a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,7 +14,7 @@ </nav> </div> {% set section_item = get_section(path="_index.md") %} - {% if recent %} + {% if config.extra.recent | default(value=true) %} <div class="toc"> <div class="toc-sticky"> <h3>Recent Posts</h3> |
