forked from slashdotdash/jekyll-lunr-js-search
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRakefile
76 lines (63 loc) · 1.95 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'rake'
require 'jsmin'
require 'fileutils'
task :default => :build
desc "Ensures all dependent JS libraries are installed and builds the gem."
task :build_gem => :build do
exec("gem build jekyll-lunr-js-custom-search.gemspec")
end
task :build => [
:bower_update,
:create_build_dir,
:copy_jekyll_plugin,
:concat_js,
:concat_css
]
task :bower_update do
abort "Please ensure bower is installed: npm install -g bower" unless system('bower install')
end
task :create_build_dir do
#Dir.mkdir('build') unless Dir.exists?('build')
end
task :copy_jekyll_plugin do
lunr_version = File.read("bower_components/lunr/VERSION").strip
open("build/jekyll_lunr_js_custom_search.rb", "w") do |concat|
Dir.glob("lib/jekyll_lunr_js_custom_search/*.rb") do |file|
ruby = File.read(file).sub(/LUNR_VERSION = .*$/, "LUNR_VERSION = \"#{lunr_version}\"")
concat.puts ruby
end
end
end
task :concat_js do
files = [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/lunr/lunr.js',
'bower_components/paginationjs/dist/pagination.min.js',
'bower_components/lodash/dist/lodash.min.js',
'bower_components/fontawesome/js/all.min.js',
'js/lunr.custom.search.js'
]
File.open('build/custom-search.js', 'w') do |file|
file.write(files.inject('') { |data, file|
data << File.read(file)
})
end
# Lunr is stored separately so we can use it for index generation
FileUtils.cp('bower_components/lunr/lunr.js', 'build/lunr.js')
end
task :concat_css do
files = [
'bower_components/paginationjs/dist/pagination.css',
'bower_components/fontawesome/css/all.min.css',
'css/custom-search.css'
]
File.open('build/custom-search.css', 'w') do |file|
file.write(files.inject('') { |data, file|
data << File.read(file)
})
end
end
#task :minify_js do
# out = JSMin.minify(File.open('build/custom-search.js', 'r').read)
# File.open('build/custom-search.min.js', 'w') {|f| f.write(out) }
#end