Skip to content

Commit

Permalink
Client side dependency management
Browse files Browse the repository at this point in the history
Create Bower config file with references to 3rd party JavaScript libs.
Add rake build task for minifying JavaScript into single
`search.min.js`.
Include minified `search.min.js` in build directory.
  • Loading branch information
Ben Smith committed Mar 22, 2014
1 parent 5bfd781 commit 9e11183
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bower_components
*.gem
*.rbc
.bundle
Expand All @@ -15,4 +16,4 @@ tmp
# YARD artifacts
.yardoc
_yardoc
doc/
doc/
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rake'
gem 'uglifier'
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GEM
remote: https://rubygems.org/
specs:
execjs (1.4.0)
multi_json (~> 1.0)
json (1.8.0)
multi_json (1.7.0)
rake (10.1.1)
uglifier (2.4.0)
execjs (>= 0.3.0)
json (>= 1.8.0)

PLATFORMS
ruby

DEPENDENCIES
rake
uglifier
41 changes: 39 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
task :build do
system('mkdir -p build; ls *.rb | while read file; do cat $file; echo ""; done > build/jekyll_lunr_js_search.rb')
require 'rake'
require 'uglifier'

task :default => :build

task :build => [:create_build_dir, :copy_jekyll_plugin, :concat_js, :minify_js] do
end

task :create_build_dir do
Dir.mkdir('build') unless Dir.exists?('build')
end

task :copy_jekyll_plugin do
system('ls *.rb | while read file; do cat $file; echo ""; done > build/jekyll_lunr_js_search.rb')
end

task :concat_js do
out = ''
files = [
'bower_components/jquery/dist/jquery.js',
'bower_components/lunr.js/lunr.js',
'bower_components/mustache/mustache.js',
'bower_components/date.format/index.js',
'bower_components/uri.js/src/URI.js',
'js/jquery.lunr.search.js'
]

files.each do |file|
out += File.read(file)
end

File.open('build/search.min.js', 'w') do |file|
file.write(out)
end
end

task :minify_js do
minified = Uglifier.compile(File.read('build/search.min.js'))
File.open('build/search.min.js', 'w') { |file| file.write(minified) }
end
28 changes: 28 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "jekyll-lunr-js-search",
"version": "0.0.1",
"homepage": "https://github.com/slashdotdash/jekyll-lunr-js-search",
"authors": [
"Ben Smith <[email protected]>"
],
"description": "Jekyll + lunr.js = Static websites with powerful full-text search using JavaScript.",
"keywords": [
"jekyll",
"lunr",
"search"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"build"
],
"dependencies": {
"jquery": "~2.1.0",
"lunr.js": "~0.4.5",
"mustache": "~0.8.1",
"date.format": "http://stevenlevithan.com/assets/misc/date.format.js",
"uri.js": "~1.12.0"
}
}
79 changes: 79 additions & 0 deletions build/search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/jquery.lunr.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
LunrSearch.prototype.search = function(query) {
var entries = this.entries;

if (query.length <= 2) {
if (query.length < 2) {
this.$results.hide();
this.$entries.empty();
} else {
Expand Down

0 comments on commit 9e11183

Please sign in to comment.