jekyll_pages_api_search 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +75 -2
- data/README.md +118 -79
- data/assets/js/search-bundle.js +16 -12
- data/assets/js/search-bundle.js.gz +0 -0
- data/assets/js/search.js +90 -64
- data/assets/png/search.png +0 -0
- data/assets/svg/search.svg +6 -0
- data/lib/jekyll_pages_api_search.rb +9 -9
- data/lib/jekyll_pages_api_search/assets.rb +32 -2
- data/lib/jekyll_pages_api_search/compressor.rb +2 -2
- data/lib/jekyll_pages_api_search/config.rb +20 -0
- data/lib/jekyll_pages_api_search/generator.rb +17 -0
- data/lib/jekyll_pages_api_search/layouts/search-results.html +11 -0
- data/lib/jekyll_pages_api_search/lunr.min.js +2 -2
- data/lib/jekyll_pages_api_search/sass/jekyll_pages_api_search.scss +16 -33
- data/lib/jekyll_pages_api_search/search.html +9 -17
- data/lib/jekyll_pages_api_search/search.js +34 -17
- data/lib/jekyll_pages_api_search/search.rb +17 -13
- data/lib/jekyll_pages_api_search/search_hook.rb +5 -5
- data/lib/jekyll_pages_api_search/search_page.rb +30 -0
- data/lib/jekyll_pages_api_search/search_page_layouts.rb +42 -0
- data/lib/jekyll_pages_api_search/standalone.rb +3 -3
- data/lib/jekyll_pages_api_search/tags.rb +15 -1
- data/lib/jekyll_pages_api_search/version.rb +1 -1
- metadata +9 -17
- data/lib/jekyll_pages_api_search/js_copier.rb +0 -33
Binary file
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- Generated by IcoMoon.io -->
|
3
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
4
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="26" height="28" viewBox="0 0 26 28">
|
5
|
+
<path fill="#444" d="M18 13q0-2.891-2.055-4.945t-4.945-2.055-4.945 2.055-2.055 4.945 2.055 4.945 4.945 2.055 4.945-2.055 2.055-4.945zM26 26q0 0.812-0.594 1.406t-1.406 0.594q-0.844 0-1.406-0.594l-5.359-5.344q-2.797 1.937-6.234 1.937-2.234 0-4.273-0.867t-3.516-2.344-2.344-3.516-0.867-4.273 0.867-4.273 2.344-3.516 3.516-2.344 4.273-0.867 4.273 0.867 3.516 2.344 2.344 3.516 0.867 4.273q0 3.437-1.937 6.234l5.359 5.359q0.578 0.578 0.578 1.406z"></path>
|
6
|
+
</svg>
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# @author Mike Bland (michael.bland@gsa.gov)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
require_relative './jekyll_pages_api_search/assets'
|
4
|
+
require_relative './jekyll_pages_api_search/generator'
|
5
|
+
require_relative './jekyll_pages_api_search/sass'
|
6
|
+
require_relative './jekyll_pages_api_search/search'
|
7
|
+
require_relative './jekyll_pages_api_search/search_hook'
|
8
|
+
require_relative './jekyll_pages_api_search/site'
|
9
|
+
require_relative './jekyll_pages_api_search/standalone'
|
10
|
+
require_relative './jekyll_pages_api_search/tags'
|
11
|
+
require_relative './jekyll_pages_api_search/version'
|
@@ -1,17 +1,47 @@
|
|
1
1
|
# @author Mike Bland (michael.bland@gsa.gov)
|
2
2
|
|
3
|
-
require_relative 'sass'
|
4
|
-
require_relative 'tags'
|
3
|
+
require_relative './sass'
|
4
|
+
require_relative './tags'
|
5
5
|
|
6
6
|
require 'fileutils'
|
7
|
+
require 'jekyll/static_file'
|
7
8
|
|
8
9
|
module JekyllPagesApiSearch
|
9
10
|
class Assets
|
11
|
+
SOURCE = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
12
|
+
JAVASCRIPT_DIR = File.join('assets', 'js')
|
13
|
+
BEGIN_PATH = SOURCE.size + File::SEPARATOR.size
|
14
|
+
|
15
|
+
def self.copy_to_site(site)
|
16
|
+
asset_paths.each do |file_path|
|
17
|
+
site.static_files << ::Jekyll::StaticFile.new(
|
18
|
+
site, SOURCE, File.dirname(file_path), File.basename(file_path))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.copy_to_basedir(basedir)
|
23
|
+
asset_paths.each do |asset|
|
24
|
+
target_path = File.join(basedir, asset)
|
25
|
+
target_dir = File.dirname(target_path)
|
26
|
+
FileUtils.mkdir_p(target_dir) if !Dir.exist?(target_dir)
|
27
|
+
FileUtils.cp(File.join(SOURCE, asset), target_path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
10
31
|
def self.write_to_files(baseurl, scss, html, js)
|
11
32
|
[scss, html, js].each {|i| FileUtils.mkdir_p File.dirname(i)}
|
12
33
|
FileUtils.cp Sass::INTERFACE_FILE, scss
|
13
34
|
File.open(html, 'w') {|f| f << SearchInterfaceTag::CODE}
|
14
35
|
File.open(js, 'w') {|f| f << LoadSearchTag::generate_script(baseurl)}
|
15
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def self.asset_paths
|
41
|
+
js_pattern = File.join(SOURCE, JAVASCRIPT_DIR, 'search-bundle.js*')
|
42
|
+
img_pattern = File.join(SOURCE, 'assets', '{png,svg}', '*')
|
43
|
+
all_paths = Dir.glob(js_pattern) + Dir.glob(img_pattern)
|
44
|
+
all_paths.map { |path| path[BEGIN_PATH..-1] }
|
45
|
+
end
|
16
46
|
end
|
17
47
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'fileutils'
|
3
2
|
require 'zlib'
|
4
3
|
|
5
4
|
module JekyllPagesApiSearch
|
@@ -9,6 +8,7 @@ module JekyllPagesApiSearch
|
|
9
8
|
::Zlib::GzipWriter.open("#{file}.gz", Zlib::BEST_COMPRESSION) do |gz|
|
10
9
|
gz.write content
|
11
10
|
end
|
11
|
+
FileUtils.touch([file, "#{file}.gz"])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module JekyllPagesApiSearch
|
2
|
+
class Config
|
3
|
+
def self.skip_index?(site)
|
4
|
+
search_config = site.config['jekyll_pages_api_search']
|
5
|
+
return true if search_config.nil?
|
6
|
+
skip_index_value = search_config['skip_index']
|
7
|
+
return skip_index_value unless skip_index_value.nil?
|
8
|
+
search_config['skip_index'] = !node_installed?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.node_installed?
|
12
|
+
$stdout.write('jekyll_pages_api_search: checking for Node.js: ')
|
13
|
+
return true if system('node', '-v')
|
14
|
+
puts('not generating search index because Node.js not found; check ' \
|
15
|
+
'your PATH environment variable or visit https://nodejs.org/ ' \
|
16
|
+
'to download Node.js for your system')
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative './assets'
|
2
|
+
require_relative './config'
|
3
|
+
require_relative './search_page'
|
4
|
+
require_relative './search_page_layouts'
|
5
|
+
|
6
|
+
require 'jekyll'
|
7
|
+
|
8
|
+
module JekyllPagesApiSearch
|
9
|
+
class Generator < ::Jekyll::Generator
|
10
|
+
def generate(site)
|
11
|
+
return if Config.skip_index?(site)
|
12
|
+
JekyllPagesApiSearch::SearchPageLayouts.register(site)
|
13
|
+
site.pages << JekyllPagesApiSearch::SearchPage.new(site)
|
14
|
+
JekyllPagesApiSearch::Assets.copy_to_site(site)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
|
-
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.
|
2
|
+
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.6.0
|
3
3
|
* Copyright (C) 2015 Oliver Nightingale
|
4
4
|
* MIT Licensed
|
5
5
|
* @license
|
6
6
|
*/
|
7
|
-
!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.9",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(e<i.idx)return this.list=new t.Vector.Node(e,n,i),this.length++;for(var o=i,r=i.next;void 0!=r;){if(e<r.idx)return o.next=new t.Vector.Node(e,n,r),this.length++;o=r,r=r.next}return o.next=new t.Vector.Node(e,n,r),this.length++},t.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var t,e=this.list,n=0;e;)t=e.val,n+=t*t,e=e.next;return this._magnitude=Math.sqrt(n)},t.Vector.prototype.dot=function(t){for(var e=this.list,n=t.list,i=0;e&&n;)e.idx<n.idx?e=e.next:e.idx>n.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;t<arguments.length;t++)e=arguments[t],~this.indexOf(e)||this.elements.splice(this.locationFor(e),0,e);this.length=this.elements.length},t.SortedSet.prototype.toArray=function(){return this.elements.slice()},t.SortedSet.prototype.map=function(t,e){return this.elements.map(t,e)},t.SortedSet.prototype.forEach=function(t,e){return this.elements.forEach(t,e)},t.SortedSet.prototype.indexOf=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;){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]?i++: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;s<o.length;s++){var a=o.elements[s],h=this._fields.reduce(function(t,e){var n=i[e.name].length;if(!n)return t;var o=i[e.name].filter(function(t){return t===a}).length;return t+o/n*e.boost},0);this.tokenStore.add(a,{ref:r,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.tokenStore.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),f=new RegExp(l),d=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,m=/^(.+?)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=d,a=v,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=m,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=f,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;n<t.length;n++){if(!e[t[n]])return!1;e=e[t[n]]}return!0},t.TokenStore.prototype.getNode=function(t){if(!t)return{};for(var e=this.root,n=0;n<t.length;n++){if(!e[t[n]])return{};e=e[t[n]]}return e},t.TokenStore.prototype.get=function(t,e){return this.getNode(t,e).docs||{}},t.TokenStore.prototype.count=function(t,e){return Object.keys(this.get(t,e)).length},t.TokenStore.prototype.remove=function(t,e){if(t){for(var n=this.root,i=0;i<t.length;i++){if(!(t[i]in n))return;n=n[t[i]]}delete n.docs[e]}},t.TokenStore.prototype.expand=function(t,e){var n=this.getNode(t),i=n.docs||{},e=e||[];return Object.keys(i).length&&e.push(t),Object.keys(n).forEach(function(n){"docs"!==n&&e.concat(this.expand(t+n,e))},this),e},t.TokenStore.prototype.toJSON=function(){return{root:this.root,length:this.length}},function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.lunr=e()}(this,function(){return t})}();
|
7
|
+
!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.6.0",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.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(e<i.idx)return this.list=new t.Vector.Node(e,n,i),this.length++;for(var r=i,o=i.next;void 0!=o;){if(e<o.idx)return r.next=new t.Vector.Node(e,n,o),this.length++;r=o,o=o.next}return r.next=new t.Vector.Node(e,n,o),this.length++},t.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var t,e=this.list,n=0;e;)t=e.val,n+=t*t,e=e.next;return this._magnitude=Math.sqrt(n)},t.Vector.prototype.dot=function(t){for(var e=this.list,n=t.list,i=0;e&&n;)e.idx<n.idx?e=e.next:e.idx>n.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;t<arguments.length;t++)e=arguments[t],~this.indexOf(e)||this.elements.splice(this.locationFor(e),0,e);this.length=this.elements.length},t.SortedSet.prototype.toArray=function(){return this.elements.slice()},t.SortedSet.prototype.map=function(t,e){return this.elements.map(t,e)},t.SortedSet.prototype.forEach=function(t,e){return this.elements.forEach(t,e)},t.SortedSet.prototype.indexOf=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;){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]?i++: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;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={},r=new t.SortedSet,o=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=o,t.SortedSet.prototype.add.apply(r,o)},this),this.documentStore.set(o,r),t.SortedSet.prototype.add.apply(this.corpusTokens,r.toArray());for(var s=0;s<r.length;s++){var a=r.elements[s],h=this._fields.reduce(function(t,e){var n=i[e.name].length;if(!n)return t;var r=i[e.name].filter(function(t){return t===a}).length;return t+r/n*e.boost},0);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(t.tokenizer(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),p=Object.keys(f),d=p.length,v=0;d>v;v++)l.add(f[p[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,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),p=new RegExp(u),d=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,m=/^(.+?)eed$/,g=/^(.+?)(ed|ing)$/,y=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+r+i+"[^aeiouwxy]$"),k=/^(.+?[^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)$/,_=/^(.+?)(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("^"+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=d,a=v,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=m,a=g,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=p,a.test(i)&&(n=i,a=S,h=w,u=x,a.test(n)?n+="e":h.test(n)?(s=y,n=n.replace(s,"")):u.test(n)&&(n+="e"))}if(s=k,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=_,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=f,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"==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;n<t.length;n++){if(!e[t.charAt(n)])return!1;e=e[t.charAt(n)]}return!0},t.TokenStore.prototype.getNode=function(t){if(!t)return{};for(var e=this.root,n=0;n<t.length;n++){if(!e[t.charAt(n)])return{};e=e[t.charAt(n)]}return e},t.TokenStore.prototype.get=function(t,e){return this.getNode(t,e).docs||{}},t.TokenStore.prototype.count=function(t,e){return Object.keys(this.get(t,e)).length},t.TokenStore.prototype.remove=function(t,e){if(t){for(var n=this.root,i=0;i<t.length;i++){if(!(t.charAt(i)in n))return;n=n[t.charAt(i)]}delete n.docs[e]}},t.TokenStore.prototype.expand=function(t,e){var n=this.getNode(t),i=n.docs||{},e=e||[];return Object.keys(i).length&&e.push(t),Object.keys(n).forEach(function(n){"docs"!==n&&e.concat(this.expand(t+n,e))},this),e},t.TokenStore.prototype.toJSON=function(){return{root:this.root,length:this.length}},function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.lunr=e()}(this,function(){return t})}();
|
@@ -1,38 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
padding: 0px;
|
6
|
-
z-index: 99999!important;
|
7
|
-
position: fixed;
|
8
|
-
background-color: white;
|
9
|
-
/*max-height:200px;*/
|
10
|
-
border-collapse: separate;
|
11
|
-
overflow-y: hidden;
|
12
|
-
|
13
|
-
li {
|
14
|
-
cursor: pointer;
|
15
|
-
padding-left: 1px;
|
16
|
-
text-align: left;
|
17
|
-
list-style: none;
|
18
|
-
line-height: 20px;
|
19
|
-
list-style-image: none;
|
20
|
-
list-style-position: outside;
|
21
|
-
list-style-type: none;
|
22
|
-
}
|
23
|
-
|
24
|
-
li.selected,
|
25
|
-
li:hover {
|
26
|
-
background-color: #ededed;
|
27
|
-
}
|
28
|
-
|
29
|
-
b {
|
30
|
-
color: blue;
|
1
|
+
@media screen and (min-width: 45em) {
|
2
|
+
div.search-interface{
|
3
|
+
width: 30%;
|
4
|
+
float: right;
|
31
5
|
}
|
6
|
+
}
|
32
7
|
|
33
|
-
|
34
|
-
|
35
|
-
|
8
|
+
div.search-interface input {
|
9
|
+
display: block;
|
10
|
+
-webkit-box-sizing: border-box;
|
11
|
+
width: 100%;
|
12
|
+
padding: 6px 4px;
|
13
|
+
padding-left: 2em;
|
14
|
+
font: inherit;
|
15
|
+
border-radius: 3px;
|
16
|
+
border: 1px solid #ccc;
|
17
|
+
background: url(../svg/search.svg) 6px 45% no-repeat;
|
18
|
+
background-size: 16px;
|
36
19
|
}
|
37
20
|
|
38
21
|
.sr-only { //for screen readers
|
@@ -1,18 +1,10 @@
|
|
1
|
-
<div
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
ng-keydown="searchKeyDown($event)"
|
11
|
-
placeholder="Search - click or press '/'"
|
12
|
-
aria-autocomplete="list"
|
13
|
-
aria-activedescendant="search_result_0"
|
14
|
-
aria-haspopup="true"
|
15
|
-
></live-search>
|
16
|
-
</div>
|
17
|
-
<div ng-hide="searchText"></div>
|
1
|
+
<div class="search-interface">
|
2
|
+
<form action="{{ search_endpoint }}">
|
3
|
+
<div class="field">
|
4
|
+
<label>
|
5
|
+
<input type="search" id="search-input" name="q"
|
6
|
+
placeholder="Search - click or press '/'">
|
7
|
+
</label>
|
8
|
+
</div>
|
9
|
+
</form>
|
18
10
|
</div>
|
@@ -1,24 +1,41 @@
|
|
1
|
-
|
1
|
+
var lunr = require('./lunr.min');
|
2
|
+
var input = '';
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
function buildIndex(corpus, indexFields) {
|
5
|
+
var index,
|
6
|
+
urlToDoc = {};
|
7
|
+
|
8
|
+
index = lunr(function() {
|
9
|
+
var boost;
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
this.ref('url');
|
12
|
+
|
13
|
+
for (var fieldName in indexFields) {
|
14
|
+
boost = indexFields[fieldName];
|
15
|
+
this.field(fieldName, boost);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
19
|
+
corpus.entries.forEach(function(page) {
|
20
|
+
if (page.skip_index !== true) {
|
21
|
+
index.add(page);
|
22
|
+
urlToDoc[page.url] = {url: page.url, title: page.title};
|
23
|
+
}
|
24
|
+
});
|
25
|
+
|
26
|
+
return JSON.stringify({
|
27
|
+
index: index.toJSON(),
|
28
|
+
urlToDoc: urlToDoc
|
29
|
+
});
|
30
|
+
}
|
11
31
|
|
12
|
-
|
32
|
+
process.stdin.setEncoding('utf8');
|
13
33
|
|
14
|
-
|
15
|
-
|
16
|
-
index.add(page);
|
17
|
-
url_to_doc[page.url] = {url: page.url, title: page.title};
|
18
|
-
}
|
34
|
+
process.stdin.on('data', function(data) {
|
35
|
+
input = input + data;
|
19
36
|
});
|
20
37
|
|
21
|
-
|
22
|
-
|
23
|
-
|
38
|
+
process.stdin.on('end', function() {
|
39
|
+
input = JSON.parse(input);
|
40
|
+
process.stdout.write(buildIndex(input.corpus, input.indexFields));
|
24
41
|
});
|
@@ -1,32 +1,36 @@
|
|
1
1
|
# @author Mike Bland (michael.bland@gsa.gov)
|
2
2
|
|
3
3
|
require 'jekyll_pages_api'
|
4
|
-
require '
|
4
|
+
require 'json'
|
5
5
|
|
6
6
|
module JekyllPagesApiSearch
|
7
7
|
class SearchIndexBuilder
|
8
|
-
|
8
|
+
DIRNAME = File.dirname(__FILE__).freeze
|
9
|
+
COMPILE_SCRIPT = File.join(DIRNAME, 'search.js').freeze
|
10
|
+
INDEX_FILE = 'search-index.json'.freeze
|
9
11
|
|
10
12
|
def self.build_index(site)
|
11
13
|
corpus_page = find_corpus_page(site.pages)
|
12
14
|
raise 'Pages API corpus not found' if corpus_page == nil
|
13
15
|
|
14
|
-
dirname = File.dirname(__FILE__)
|
15
16
|
search_config = site.config['jekyll_pages_api_search']
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
index_page = JekyllPagesApi::PageWithoutAFile.new(
|
23
|
-
site, site.source, '', INDEX_FILE)
|
24
|
-
index_page.output = cxt[:result]
|
25
|
-
return index_page
|
17
|
+
index_fields = JSON.generate(search_config['index_fields'] || {})
|
18
|
+
input = "{\"corpus\": #{corpus_page.output}," \
|
19
|
+
"\"indexFields\": #{index_fields}}"
|
20
|
+
compile(input,
|
21
|
+
JekyllPagesApi::PageWithoutAFile.new(site, site.source, '', INDEX_FILE))
|
26
22
|
end
|
27
23
|
|
28
24
|
def self.find_corpus_page(pages)
|
29
25
|
pages.each {|page| return page if page.name == 'pages.json'}
|
30
26
|
end
|
27
|
+
|
28
|
+
def self.compile(input, index_page)
|
29
|
+
compiler = open("|node #{COMPILE_SCRIPT}", File::RDWR)
|
30
|
+
compiler.puts(input)
|
31
|
+
compiler.close_write
|
32
|
+
index_page.output = compiler.gets
|
33
|
+
index_page
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# @author Mike Bland (michael.bland@gsa.gov)
|
2
2
|
|
3
|
-
require_relative 'compressor'
|
4
|
-
require_relative '
|
3
|
+
require_relative './compressor'
|
4
|
+
require_relative './config'
|
5
|
+
require_relative './search_page'
|
6
|
+
require_relative './search_page_layouts'
|
5
7
|
|
6
8
|
require 'jekyll/site'
|
7
9
|
require 'jekyll_pages_api'
|
@@ -17,15 +19,13 @@ module Jekyll
|
|
17
19
|
alias_method :orig_write, :write
|
18
20
|
|
19
21
|
def skip_index?
|
20
|
-
|
21
|
-
search_config.nil? || search_config['skip_index']
|
22
|
+
@skip_index ||= JekyllPagesApiSearch::Config.skip_index?(self)
|
22
23
|
end
|
23
24
|
|
24
25
|
def after_render
|
25
26
|
pages_api_after_render
|
26
27
|
return if skip_index?
|
27
28
|
self.pages << JekyllPagesApiSearch::SearchIndexBuilder.build_index(self)
|
28
|
-
JekyllPagesApiSearch::JavascriptCopier.copy_to_site(self)
|
29
29
|
end
|
30
30
|
|
31
31
|
def write
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
|
3
|
+
module JekyllPagesApiSearch
|
4
|
+
class SearchPage < ::Jekyll::Page
|
5
|
+
DEFAULT_TITLE = 'Search results'
|
6
|
+
DEFAULT_ENDPOINT = 'search'
|
7
|
+
|
8
|
+
def initialize(site)
|
9
|
+
@site = site
|
10
|
+
@name = 'index.html'
|
11
|
+
|
12
|
+
process(@name)
|
13
|
+
@data = {}
|
14
|
+
search_config = site.config['jekyll_pages_api_search']
|
15
|
+
data['title'] = search_config['results_page_title'] || DEFAULT_TITLE
|
16
|
+
data['permalink'] = endpoint(site.config, search_config)
|
17
|
+
data['layout'] = (
|
18
|
+
search_config['layout'] || SearchPageLayouts::DEFAULT_LAYOUT)
|
19
|
+
data['skip_index'] = true
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def endpoint(site_config, search_config)
|
25
|
+
baseurl = "#{site_config['baseurl'] || ''}"
|
26
|
+
search_endpoint = search_config['endpoint'] || DEFAULT_ENDPOINT
|
27
|
+
"/#{baseurl}/#{search_endpoint}/".gsub(/\/+/, '/')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'jekyll'
|
2
|
+
require 'safe_yaml'
|
3
|
+
|
4
|
+
module JekyllPagesApiSearch
|
5
|
+
# We have to essentially recreate the ::Jekyll::Layout constructor to loosen
|
6
|
+
# the default restriction that layouts be included in the site source.
|
7
|
+
#
|
8
|
+
# Copied from guides_style_18f/layouts.rb. Could probably be extracted into
|
9
|
+
# another gem.
|
10
|
+
class SearchPageLayouts < ::Jekyll::Layout
|
11
|
+
DEFAULT_LAYOUT = 'search-results'
|
12
|
+
LAYOUTS_DIR = File.join(File.dirname(__FILE__), 'layouts')
|
13
|
+
|
14
|
+
private_class_method :new
|
15
|
+
|
16
|
+
def initialize(site, layout_name)
|
17
|
+
@site = site
|
18
|
+
@base = LAYOUTS_DIR
|
19
|
+
@name = "#{layout_name}.html"
|
20
|
+
@path = File.join(@base, @name)
|
21
|
+
parse_content_and_data(File.join(@base, name))
|
22
|
+
process(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_content_and_data(file_path)
|
26
|
+
@data = {}
|
27
|
+
@content = File.read(file_path)
|
28
|
+
|
29
|
+
front_matter_pattern = /^(---\n.*)---\n/m
|
30
|
+
front_matter_match = front_matter_pattern.match(content)
|
31
|
+
return unless front_matter_match
|
32
|
+
|
33
|
+
@content = front_matter_match.post_match
|
34
|
+
@data = SafeYAML.load(front_matter_match[1], safe: true) || {}
|
35
|
+
end
|
36
|
+
private :parse_content_and_data
|
37
|
+
|
38
|
+
def self.register(site)
|
39
|
+
site.layouts[DEFAULT_LAYOUT] ||= new(site, DEFAULT_LAYOUT)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|