diff --git a/brainstew.css b/brainstew.css index e69de29..2401279 100644 --- a/brainstew.css +++ b/brainstew.css @@ -0,0 +1,46 @@ +.header { + position: relative; + z-index: 10; +} + +#search-input { + float: right; + display: none; +} +#search-button { + float: right; + text-indent: -10000px; + background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAQAAAC1QeVaAAAAAnNCSVQICFXsRgQAAAAJcEhZcwAADdcAAA3XAUIom3gAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAx0lEQVQY033PTwqCQBQG8GkjdICENmVbpfISQoWffwJPVoJeIFDoBF2gtrloVZA30EAQhOkJjeOiesPAfPx4M28Yo8IMMXLUtCNPY/1yVniBd6t0rI6oq6WDqwcKDCR0LjZTgXFL8h6klEMRcnBX7z2yIHwIrMEDRWIwJKwEPikYEu0l5bvAiELS2QBHcHv3SZ6Gkjh158GQuojQeKYcwULR+2dDO/NVOf4EIR6ocHf2GxNX4tt2zL7VevSXfRUZ8YWxX3y2T2+KPGKNWhiWHQAAAABJRU5ErkJggg==) center center no-repeat; + border: none; + width: 26px; + height: 26px; +} + +#search-results { + display: none; + position: absolute; + background: white; + max-width: 58em; + width: 100%; + min-height: 10em; + top: 3em; +} + +.body.search-dim { + opacity: 0.05; +} + +#search-results ul { + list-style: none; +} + +#search-results ul li a { + display: block; + border: 1px solid #666; + padding: 1ex; +} + +#search-results ul li a:hover { + text-decoration: none; + background: #ddd; +} diff --git a/brainstew.js b/brainstew.js index e69de29..f26c492 100644 --- a/brainstew.js +++ b/brainstew.js @@ -0,0 +1,58 @@ +$(function() { + var search_button = $(''); + var search_input = $(''); + var search_results = $('
'); + var search_index = null; + var pages = Object(); + search_results.prependTo($('div.header')); + search_input.prependTo($('div.header')); + search_button.prependTo($('div.header')); + $(search_button).click(function() { + search_input.toggle(); + if ($('#search-input:visible').length == 0) { + search_results.hide(); + search_input.val(''); + } else { + search_input.focus(); + } + $('.body').toggleClass('search-dim'); + if (search_index === null) { + $('').appendTo('body'); + $('').appendTo('body'); + $('').appendTo('body'); + search_index = lunr(function () { + this.use(lunr.fr); + this.field('title', {boost: 10}) + this.field('other_titles', {boost: 5}) + this.field('text') + this.ref('id') + }); + $.ajax({ + type: 'GET', + url: 'pages.json', + success: function(data) { + $(data).each(function(index, elem) { + pages[elem.id] = elem.title; + search_index.add(elem); + }); + }, + dataType: 'json', + async: true + }); + } + }); + $(search_input).keyup(function() { + var search_txt = $(search_input).val(); + $('#search-results').show(); + $('#search-results ul').empty(); + if (search_txt.length > 3 && search_index) { + console.log('search txt:', search_txt); + var results = search_index.search(search_txt); + $(results).each(function(index, elem) { + console.log(elem); + $('
  • ' + pages[elem.ref] + '
  • ').appendTo('#search-results ul'); + }); + console.log(results); + } + }); +}); diff --git a/js/lunr.fr.min.js b/js/lunr.fr.min.js new file mode 100644 index 0000000..1584226 --- /dev/null +++ b/js/lunr.fr.min.js @@ -0,0 +1,18 @@ +/*! + * Lunr languages, `French` language + * https://github.com/MihaiValentin/lunr-languages + * + * Copyright 2014, Mihai Valentin + * http://www.mozilla.org/MPL/ + */ +/*! + * based on + * Snowball JavaScript Library v0.3 + * http://code.google.com/p/urim/ + * http://snowball.tartarus.org/ + * + * Copyright 2010, Oleg Mazko + * http://www.mozilla.org/MPL/ + */ + +!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if("undefined"==typeof e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if("undefined"==typeof e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.fr=function(){this.pipeline.reset(),this.pipeline.add(e.fr.stopWordFilter,e.fr.stemmer)},e.fr.stemmer=function(){var r=e.stemmerSupport.Among,s=e.stemmerSupport.SnowballProgram,i=new function(){function e(e,r,s){return P.eq_s(1,e)&&(P.ket=P.cursor,P.in_grouping(C,97,251))?(P.slice_from(r),P.cursor=s,!0):!1}function i(e,r,s){return P.eq_s(1,e)?(P.ket=P.cursor,P.slice_from(r),P.cursor=s,!0):!1}function n(){for(var r,s;;){if(r=P.cursor,P.in_grouping(C,97,251)){if(P.bra=P.cursor,s=P.cursor,e("u","U",r))continue;if(P.cursor=s,e("i","I",r))continue;if(P.cursor=s,i("y","Y",r))continue}if(P.cursor=r,P.bra=r,!e("y","Y",r)){if(P.cursor=r,P.eq_s(1,"q")&&(P.bra=P.cursor,i("u","U",r)))continue;if(P.cursor=r,r>=P.limit)return;P.cursor++}}}function t(){for(;!P.in_grouping(C,97,251);){if(P.cursor>=P.limit)return!0;P.cursor++}for(;!P.out_grouping(C,97,251);){if(P.cursor>=P.limit)return!0;P.cursor++}return!1}function o(){var e=P.cursor;if(q=P.limit,g=q,p=q,P.in_grouping(C,97,251)&&P.in_grouping(C,97,251)&&P.cursor=P.limit){P.cursor=q;break}P.cursor++}while(!P.in_grouping(C,97,251))}q=P.cursor,P.cursor=e,t()||(g=P.cursor,t()||(p=P.cursor))}function u(){for(var e,r;;){if(r=P.cursor,P.bra=r,e=P.find_among(z,4),!e)break;switch(P.ket=P.cursor,e){case 1:P.slice_from("i");break;case 2:P.slice_from("u");break;case 3:P.slice_from("y");break;case 4:if(P.cursor>=P.limit)return;P.cursor++}}}function c(){return q<=P.cursor}function a(){return g<=P.cursor}function l(){return p<=P.cursor}function w(){var e,r;if(P.ket=P.cursor,e=P.find_among_b(W,43)){switch(P.bra=P.cursor,e){case 1:if(!l())return!1;P.slice_del();break;case 2:if(!l())return!1;P.slice_del(),P.ket=P.cursor,P.eq_s_b(2,"ic")&&(P.bra=P.cursor,l()?P.slice_del():P.slice_from("iqU"));break;case 3:if(!l())return!1;P.slice_from("log");break;case 4:if(!l())return!1;P.slice_from("u");break;case 5:if(!l())return!1;P.slice_from("ent");break;case 6:if(!c())return!1;if(P.slice_del(),P.ket=P.cursor,e=P.find_among_b(h,6))switch(P.bra=P.cursor,e){case 1:l()&&(P.slice_del(),P.ket=P.cursor,P.eq_s_b(2,"at")&&(P.bra=P.cursor,l()&&P.slice_del()));break;case 2:l()?P.slice_del():a()&&P.slice_from("eux");break;case 3:l()&&P.slice_del();break;case 4:c()&&P.slice_from("i")}break;case 7:if(!l())return!1;if(P.slice_del(),P.ket=P.cursor,e=P.find_among_b(y,3))switch(P.bra=P.cursor,e){case 1:l()?P.slice_del():P.slice_from("abl");break;case 2:l()?P.slice_del():P.slice_from("iqU");break;case 3:l()&&P.slice_del()}break;case 8:if(!l())return!1;if(P.slice_del(),P.ket=P.cursor,P.eq_s_b(2,"at")&&(P.bra=P.cursor,l()&&(P.slice_del(),P.ket=P.cursor,P.eq_s_b(2,"ic")))){P.bra=P.cursor,l()?P.slice_del():P.slice_from("iqU");break}break;case 9:P.slice_from("eau");break;case 10:if(!a())return!1;P.slice_from("al");break;case 11:if(l())P.slice_del();else{if(!a())return!1;P.slice_from("eux")}break;case 12:if(!a()||!P.out_grouping_b(C,97,251))return!1;P.slice_del();break;case 13:return c()&&P.slice_from("ant"),!1;case 14:return c()&&P.slice_from("ent"),!1;case 15:return r=P.limit-P.cursor,P.in_grouping_b(C,97,251)&&c()&&(P.cursor=P.limit-r,P.slice_del()),!1}return!0}return!1}function f(){var e,r;if(P.cursor=q){if(s=P.limit_backward,P.limit_backward=q,P.ket=P.cursor,e=P.find_among_b(I,7))switch(P.bra=P.cursor,e){case 1:if(l()){if(i=P.limit-P.cursor,!P.eq_s_b(1,"s")&&(P.cursor=P.limit-i,!P.eq_s_b(1,"t")))break;P.slice_del()}break;case 2:P.slice_from("i");break;case 3:P.slice_del();break;case 4:P.eq_s_b(2,"gu")&&P.slice_del()}P.limit_backward=s}}function b(){var e=P.limit-P.cursor;P.find_among_b(U,5)&&(P.cursor=P.limit-e,P.ket=P.cursor,P.cursor>P.limit_backward&&(P.cursor--,P.bra=P.cursor,P.slice_del()))}function d(){for(var e,r=1;P.out_grouping_b(C,97,251);)r--;if(0>=r){if(P.ket=P.cursor,e=P.limit-P.cursor,!P.eq_s_b(1,"é")&&(P.cursor=P.limit-e,!P.eq_s_b(1,"è")))return;P.bra=P.cursor,P.slice_from("e")}}function k(){return w()||(P.cursor=P.limit,f()||(P.cursor=P.limit,m()))?(P.cursor=P.limit,P.ket=P.cursor,void(P.eq_s_b(1,"Y")?(P.bra=P.cursor,P.slice_from("i")):(P.cursor=P.limit,P.eq_s_b(1,"ç")&&(P.bra=P.cursor,P.slice_from("c"))))):(P.cursor=P.limit,void _())}var p,g,q,v=[new r("col",-1,-1),new r("par",-1,-1),new r("tap",-1,-1)],z=[new r("",-1,4),new r("I",0,1),new r("U",0,2),new r("Y",0,3)],h=[new r("iqU",-1,3),new r("abl",-1,3),new r("Ièr",-1,4),new r("ièr",-1,4),new r("eus",-1,2),new r("iv",-1,1)],y=[new r("ic",-1,2),new r("abil",-1,1),new r("iv",-1,3)],W=[new r("iqUe",-1,1),new r("atrice",-1,2),new r("ance",-1,1),new r("ence",-1,5),new r("logie",-1,3),new r("able",-1,1),new r("isme",-1,1),new r("euse",-1,11),new r("iste",-1,1),new r("ive",-1,8),new r("if",-1,8),new r("usion",-1,4),new r("ation",-1,2),new r("ution",-1,4),new r("ateur",-1,2),new r("iqUes",-1,1),new r("atrices",-1,2),new r("ances",-1,1),new r("ences",-1,5),new r("logies",-1,3),new r("ables",-1,1),new r("ismes",-1,1),new r("euses",-1,11),new r("istes",-1,1),new r("ives",-1,8),new r("ifs",-1,8),new r("usions",-1,4),new r("ations",-1,2),new r("utions",-1,4),new r("ateurs",-1,2),new r("ments",-1,15),new r("ements",30,6),new r("issements",31,12),new r("ités",-1,7),new r("ment",-1,15),new r("ement",34,6),new r("issement",35,12),new r("amment",34,13),new r("emment",34,14),new r("aux",-1,10),new r("eaux",39,9),new r("eux",-1,1),new r("ité",-1,7)],x=[new r("ira",-1,1),new r("ie",-1,1),new r("isse",-1,1),new r("issante",-1,1),new r("i",-1,1),new r("irai",4,1),new r("ir",-1,1),new r("iras",-1,1),new r("ies",-1,1),new r("îmes",-1,1),new r("isses",-1,1),new r("issantes",-1,1),new r("îtes",-1,1),new r("is",-1,1),new r("irais",13,1),new r("issais",13,1),new r("irions",-1,1),new r("issions",-1,1),new r("irons",-1,1),new r("issons",-1,1),new r("issants",-1,1),new r("it",-1,1),new r("irait",21,1),new r("issait",21,1),new r("issant",-1,1),new r("iraIent",-1,1),new r("issaIent",-1,1),new r("irent",-1,1),new r("issent",-1,1),new r("iront",-1,1),new r("ît",-1,1),new r("iriez",-1,1),new r("issiez",-1,1),new r("irez",-1,1),new r("issez",-1,1)],F=[new r("a",-1,3),new r("era",0,2),new r("asse",-1,3),new r("ante",-1,3),new r("ée",-1,2),new r("ai",-1,3),new r("erai",5,2),new r("er",-1,2),new r("as",-1,3),new r("eras",8,2),new r("âmes",-1,3),new r("asses",-1,3),new r("antes",-1,3),new r("âtes",-1,3),new r("ées",-1,2),new r("ais",-1,3),new r("erais",15,2),new r("ions",-1,1),new r("erions",17,2),new r("assions",17,3),new r("erons",-1,2),new r("ants",-1,3),new r("és",-1,2),new r("ait",-1,3),new r("erait",23,2),new r("ant",-1,3),new r("aIent",-1,3),new r("eraIent",26,2),new r("èrent",-1,2),new r("assent",-1,3),new r("eront",-1,2),new r("ât",-1,3),new r("ez",-1,2),new r("iez",32,2),new r("eriez",33,2),new r("assiez",33,3),new r("erez",32,2),new r("é",-1,2)],I=[new r("e",-1,3),new r("Ière",0,2),new r("ière",0,2),new r("ion",-1,1),new r("Ier",-1,2),new r("ier",-1,2),new r("ë",-1,4)],U=[new r("ell",-1,-1),new r("eill",-1,-1),new r("enn",-1,-1),new r("onn",-1,-1),new r("ett",-1,-1)],C=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,128,130,103,8,5],S=[1,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,128],P=new s;this.setCurrent=function(e){P.setCurrent(e)},this.getCurrent=function(){return P.getCurrent()},this.stem=function(){var e=P.cursor;return n(),P.cursor=e,o(),P.limit_backward=e,P.cursor=P.limit,k(),P.cursor=P.limit,b(),P.cursor=P.limit,d(),P.cursor=P.limit_backward,u(),!0}};return function(e){return i.setCurrent(e),i.stem(),i.getCurrent()}}(),e.Pipeline.registerFunction(e.fr.stemmer,"stemmer-fr"),e.fr.stopWordFilter=function(r){return-1===e.fr.stopWordFilter.stopWords.indexOf(r)?r:void 0},e.fr.stopWordFilter.stopWords=new e.SortedSet,e.fr.stopWordFilter.stopWords.length=164,e.fr.stopWordFilter.stopWords.elements=" ai aie aient aies ait as au aura aurai auraient aurais aurait auras aurez auriez aurions aurons auront aux avaient avais avait avec avez aviez avions avons ayant ayez ayons c ce ceci celà ces cet cette d dans de des du elle en es est et eu eue eues eurent eus eusse eussent eusses eussiez eussions eut eux eûmes eût eûtes furent fus fusse fussent fusses fussiez fussions fut fûmes fût fûtes ici il ils j je l la le les leur leurs lui m ma mais me mes moi mon même n ne nos notre nous on ont ou par pas pour qu que quel quelle quelles quels qui s sa sans se sera serai seraient serais serait seras serez seriez serions serons seront ses soi soient sois soit sommes son sont soyez soyons suis sur t ta te tes toi ton tu un une vos votre vous y à étaient étais était étant étiez étions été étée étées étés êtes".split(" "),e.Pipeline.registerFunction(e.fr.stopWordFilter,"stopWordFilter-fr")}}); \ No newline at end of file diff --git a/js/lunr.min.js b/js/lunr.min.js new file mode 100644 index 0000000..965230f --- /dev/null +++ b/js/lunr.min.js @@ -0,0 +1,7 @@ +/** + * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.11 + * Copyright (C) 2015 Oliver Nightingale + * MIT Licensed + * @license + */ +!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.5.11",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),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(t){return arguments.length&&null!=t&&void 0!=t?Array.isArray(t)?t.map(function(t){return t.toLowerCase()}):t.toString().trim().toLowerCase().split(/[\s\-]+/):[]},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,o=0;n>o;o++){for(var r=t[o],s=0;i>s&&(r=this._stack[s](r,o,t),void 0!==r);s++);void 0!==r&&e.push(r)}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(r===t)return o;t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o]}return r===t?o:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;)t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o];return r>t?o:t>r?o+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,o=0,r=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>r-1||o>s-1)break;a[i]!==h[o]?a[i]h[o]&&o++:(n.add(a[i]),i++,o++)}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;return this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone(),i.add.apply(i,n.toArray()),i},t.SortedSet.prototype.toJSON=function(){return this.toArray()},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.Store,this.tokenStore=new t.TokenStore,this.corpusTokens=new t.SortedSet,this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},t.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;return n._fields=e.fields,n._ref=e.ref,n.documentStore=t.Store.load(e.documentStore),n.tokenStore=t.TokenStore.load(e.tokenStore),n.corpusTokens=t.SortedSet.load(e.corpusTokens),n.pipeline=t.Pipeline.load(e.pipeline),n},t.Index.prototype.field=function(t,e){var e=e||{},n={name:t,boost:e.boost||1};return this._fields.push(n),this},t.Index.prototype.ref=function(t){return this._ref=t,this},t.Index.prototype.add=function(e,n){var i={},o=new t.SortedSet,r=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var r=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=r,t.SortedSet.prototype.add.apply(o,r)},this),this.documentStore.set(r,o),t.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var s=0;s0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(t.tokenizer(e)),i=new t.Vector,o=[],r=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*r,h=this,l=this.tokenStore.expand(e).reduce(function(n,o){var r=h.corpusTokens.indexOf(o),s=h.idf(o),l=1,u=new t.SortedSet;if(o!==e){var c=Math.max(3,o.length-e.length);l=1/Math.log(c)}return r>-1&&i.insert(r,a*s*l),Object.keys(h.tokenStore.get(o)).forEach(function(t){u.add(t)}),n.union(u)},new t.SortedSet);o.push(l)},this);var a=o.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,o=new t.Vector,r=0;i>r;r++){var s=n.elements[r],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);o.insert(this.corpusTokens.indexOf(s),a*h)}return o},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,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]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,a="^("+o+")?"+r+o+"("+r+")?$",h="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,u=new RegExp(s),c=new RegExp(h),p=new RegExp(a),d=new RegExp(l),f=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,g=/^(.+?)(ed|ing)$/,y=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+o+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,E=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,b=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,O=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+o+i+"[^aeiouwxy]$"),T=function(n){var i,o,r,s,a,h,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=f,a=m,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=v,a=g,s.test(n)){var T=s.exec(n);s=u,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,l=x,a.test(n)?n+="e":h.test(n)?(s=y,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=k,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+t[o])}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+e[o])}if(s=_,a=F,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=O,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=p,h=N,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=P,a=c,s.test(n)&&a.test(n)&&(s=y,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return-1===t.stopWordFilter.stopWords.indexOf(e)?e:void 0},t.stopWordFilter.stopWords=new t.SortedSet,t.stopWordFilter.stopWords.length=119,t.stopWordFilter.stopWords.elements=["","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[0],o=t.slice(1);return i in n||(n[i]={docs:{}}),0===o.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;ns;s++)i[s]=r.charCodeAt(s);return i},!r&&""!=r||!t&&0!=t||!i)throw"Bad Among initialisation: s:"+r+", substring_i: "+t+", result: "+i;this.s_size=r.length,this.s=this.toCharArray(r),this.substring_i=t,this.result=i,this.method=s},SnowballProgram:function(){var r;return{bra:0,ket:0,limit:0,cursor:0,limit_backward:0,setCurrent:function(t){r=t,this.cursor=0,this.limit=t.length,this.limit_backward=0,this.bra=this.cursor,this.ket=this.limit},getCurrent:function(){var t=r;return r=null,t},in_grouping:function(t,i,s){if(this.cursor=e&&e>=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor++,!0}return!1},in_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(s>=e&&e>=i&&(e-=i,t[e>>3]&1<<(7&e)))return this.cursor--,!0}return!1},out_grouping:function(t,i,s){if(this.cursors||i>e)return this.cursor++,!0;if(e-=i,!(t[e>>3]&1<<(7&e)))return this.cursor++,!0}return!1},out_grouping_b:function(t,i,s){if(this.cursor>this.limit_backward){var e=r.charCodeAt(this.cursor-1);if(e>s||i>e)return this.cursor--,!0;if(e-=i,!(t[e>>3]&1<<(7&e)))return this.cursor--,!0}return!1},eq_s:function(t,i){if(this.limit-this.cursors;s++)if(r.charCodeAt(this.cursor+s)!=i.charCodeAt(s))return!1;return this.cursor+=t,!0},eq_s_b:function(t,i){if(this.cursor-this.limit_backwards;s++)if(r.charCodeAt(this.cursor-t+s)!=i.charCodeAt(s))return!1;return this.cursor-=t,!0},find_among:function(t,i){for(var s=0,e=i,n=this.cursor,u=this.limit,o=0,h=0,c=!1;;){for(var f=s+(e-s>>1),a=0,l=h>o?o:h,_=t[f],b=l;b<_.s_size;b++){if(n+l==u){a=-1;break}if(a=r.charCodeAt(n+l)-_.s[b])break;l++}if(0>a?(e=f,h=l):(s=f,o=l),1>=e-s){if(s>0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n+_.s_size,!_.method)return _.result;var m=_.method();if(this.cursor=n+_.s_size,m)return _.result}if(s=_.substring_i,0>s)return 0}},find_among_b:function(t,i){for(var s=0,e=i,n=this.cursor,u=this.limit_backward,o=0,h=0,c=!1;;){for(var f=s+(e-s>>1),a=0,l=h>o?o:h,_=t[f],b=_.s_size-1-l;b>=0;b--){if(n-l==u){a=-1;break}if(a=r.charCodeAt(n-1-l)-_.s[b])break;l++}if(0>a?(e=f,h=l):(s=f,o=l),1>=e-s){if(s>0||e==s||c)break;c=!0}}for(;;){var _=t[s];if(o>=_.s_size){if(this.cursor=n-_.s_size,!_.method)return _.result;var m=_.method();if(this.cursor=n-_.s_size,m)return _.result}if(s=_.substring_i,0>s)return 0}},replace_s:function(t,i,s){var e=s.length-(i-t),n=r.substring(0,t),u=r.substring(i);return r=n+s+u,this.limit+=e,this.cursor>=i?this.cursor+=e:this.cursor>t&&(this.cursor=t),e},slice_check:function(){if(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>r.length)throw"faulty slice operation"},slice_from:function(r){this.slice_check(),this.replace_s(this.bra,this.ket,r)},slice_del:function(){this.slice_from("")},insert:function(r,t,i){var s=this.replace_s(r,t,i);r<=this.bra&&(this.bra+=s),r<=this.ket&&(this.ket+=s)},slice_to:function(){return this.slice_check(),r.substring(this.bra,this.ket)},eq_v_b:function(r){return this.eq_s_b(r.length,r)}}}}}}); \ No newline at end of file diff --git a/publish.py b/publish.py index 1d5313e..fa18155 100755 --- a/publish.py +++ b/publish.py @@ -6,13 +6,17 @@ import shutil import subprocess import tarfile import tempfile +import re import urllib2 import urlparse +import xml.etree.ElementTree as ET from django.template import Template, Context from django.conf import settings settings.configure() +MAL_NS = 'http://projectmallard.org/1.0/' + jhbuildrc = os.path.join(os.getcwd(), 'jhbuildrc') checkouts_directory = os.path.join(os.getcwd(), '..', 'src') web_directory = os.path.join(os.getcwd(), '..', 'web') @@ -68,13 +72,14 @@ def publish_mallard(module, branch, directory): if os.path.islink(index_html): os.unlink(index_html) + page_files = [os.path.join(help_dir, x) for x in os.listdir(help_dir) if x.endswith('.page')] cmd = ['jhbuild', '-f', jhbuildrc, 'run', 'yelp-build', 'html', '-o', output_dir, '-x'] if module.get('branch') == 'dev': cmd.append('mallard_extra_dev.xsl') else: cmd.append('mallard_extra.xsl') - cmd.extend([os.path.join(help_dir, x) for x in os.listdir(help_dir) if x.endswith('.page')]) + cmd.extend(page_files) subprocess.call(cmd, **kws) for static in ('brainstew.js', 'brainstew.css'): shutil.copy(static, output_dir) @@ -84,13 +89,29 @@ def publish_mallard(module, branch, directory): if html_files: os.symlink(html_files[0], index_html) + def remove_tags(string): + return re.sub('<.*?>', '', string, flags=re.DOTALL) + + pages = [] + for page_file in page_files: + text = open(page_file).read() + titles = re.findall('(.*)<\/title>', text) + pages.append({ + 'id': os.path.basename(page_file).rsplit('.', 1)[0], + 'title': remove_tags(titles[0]), + 'other_titles': remove_tags(' '.join(titles[1:])), + 'text': remove_tags(text), + }) + + json.dump(pages, open(os.path.join(output_dir, 'pages.json'), 'w'), indent=2) + if not os.path.exists('../mal2latex'): return temp_dir = tempfile.mkdtemp() cache_file = os.path.join(temp_dir, '%s.cache' % module_name) cmd = ['jhbuild', '-f', jhbuildrc, 'run', 'yelp-build', 'cache', '-o', cache_file] - cmd.extend([os.path.join(help_dir, x) for x in os.listdir(help_dir) if x.endswith('.page')]) + cmd.extend(page_files) subprocess.call(cmd, **kws) if os.path.exists(cache_file): @@ -162,4 +183,7 @@ for module in modules: module['branch'] = 'dev' publish_mallard(module, 'master', 'dev') +for js_file in os.listdir('js'): + shutil.copy('js/' + js_file, web_directory) + create_index(modules)