forked from pearsonca/stdio-ghana
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Rakefile
72 lines (65 loc) · 2.19 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
# courtesy of guidance at http://davidensinger.com/
#require 'bundler/setup'
require 'reduce'
require 'image_optim'
task :default => 'all'
desc "build _site/"
task :build do
puts system("jekyll build") ? "Success" : "Failed"
end
desc "minimize images"
task :minimage do
puts "\n## Compressing images"
io = ImageOptim.new(:pngout => false, :pngquant => false)
Dir["**/*.*"].reject{ |f| f['_site/'] }.each do |file|
case File.extname(file)
when ".gif", ".jpg", ".jpeg", ".png"
puts "Processing: #{file}"
io.optimize_image(file)
end
end
end
desc "minimize html"
task :minihtml do
puts "\n## Compressing html"
original = 0.0
compressed = 0
Dir["_site/**/*.*"].each do |file|
case File.extname(file)
when ".html", ".xml"
puts "Processing: #{file}"
original += File.size(file).to_f
min = Reduce.reduce(file)
File.open(file, "w") do |f|
f.write(min)
end
compressed += File.size(file)
end
end
puts "Total compression %0.2f\%" % (((original-compressed)/original)*100)
end
desc "commit _site/"
task :commit do
puts "\n## Staging modified files"
puts system("git add -A") ? "Success" : "Failed"
puts "\n## Committing a site build at #{Time.now.utc}"
puts system("git commit -m \"Build site at #{Time.now.utc}\"") ? "Success" : "Failed"
puts "\n## Pushing commits to remote"
puts system("git push origin source") ? "Success" : "Failed"
end
desc "deploy _site/"
task :deploy do
puts "\n## Deleting master branch"
puts system("git branch -D master") ? "Success" : "Failed"
puts "\n## Creating new master branch and switching to it"
puts system("git checkout -b master") ? "Success" : "Failed"
puts "\n## Forcing the _site subdirectory to be project root"
puts system("git filter-branch --subdirectory-filter _site/ -f") ? "Success" : "Failed"
puts "\n## Switching back to source branch"
puts system("git checkout source") ? "Success" : "Failed"
puts "\n## Pushing all branches to origin"
puts system("git push --all origin") ? "Success" : "Failed"
end
desc "compress images, build, compress html, commit, and deploy _site/"
task :all => [:minimage, :build, :minihtml, :commit, :deploy] do
end