-
Notifications
You must be signed in to change notification settings - Fork 43
/
Rakefile
107 lines (89 loc) · 2.83 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require "rake"
require "rake/testtask"
require "rake/clean"
task :default => [:test]
BUILD_DIR = "_build"
BUILD_FILE = File.join(BUILD_DIR, "compress.html")
directory BUILD_DIR
file BUILD_FILE => FileList["src/compress.*", BUILD_DIR] do |bf|
yaml = File.open("src/compress.yaml").read
liquid = File.open("src/compress.liquid").read
.gsub(/\s+/, " ")
.gsub(/\s+(?={)|/, "")
.gsub(/{% comment %}[^{]+{% endcomment %}/, "")
.strip
File.open bf.name, 'w' do |f|
f.puts yaml, liquid
end
end
Rake::TestTask.new :test => BUILD_FILE do |t|
t.libs << "test"
t.test_files = FileList["test/test_*.rb"]
end
task :performance => BUILD_FILE do
require "benchmark"
Dir.chdir "performance" do
buildtimes = [
"Build:\t\t" + Benchmark.measure { sh "JEKYLL_ENV=performance bundler exec jekyll build" }.to_s,
"Compress:\t" + Benchmark.measure { sh "bundle exec jekyll build --config _config_compress.yml" }.to_s,
"Blanklines:\t" + Benchmark.measure { sh "bundle exec jekyll build --config _config_blanklines.yml" }.to_s
]
puts buildtimes
end
end
CLEAN.include FileList["vnu*", "Gemfile.lock", "**/_site"]
CLOBBER.include FileList["_build/*", "_gh-pages"]
namespace :site do
task :build do
Dir.chdir "site" do
sh "bundle exec jekyll build"
end
end
task :preview do
Dir.chdir "site" do
sh "bundle exec jekyll serve --drafts"
end
end
VALIDATOR = "vnu/vnu.jar"
file VALIDATOR do |f|
sh "wget -O vnu.zip https://github.com/validator/validator/releases/download/20141006/vnu-20141013.jar.zip"
sh "unzip vnu.zip #{f.name}"
end
task :validate => [:build, VALIDATOR] do
sh "java -jar #{File.join(".", VALIDATOR)} ./site/_site"
end
task :proof => :build do
require 'html-proofer'
HTMLProofer.check_directory("./site/_site", {
:verbose => true,
:typhoeus => {
:ssl_verifypeer => false,
:ssl_verifyhost => 0}
}).run
end
task :test => [:validate, :proof]
GH_PAGES_DIR = "_gh-pages"
directory GH_PAGES_DIR
file GH_PAGES_DIR do |f|
sh "git clone [email protected]:penibelst/jekyll-compress-html #{f.name}"
end
desc "Commit the local site to the gh-pages branch and publish to GitHub Pages"
task :publish => [GH_PAGES_DIR, :test] do
Dir.chdir GH_PAGES_DIR do
sh "git checkout gh-pages"
sh "git pull origin gh-pages"
end
puts "Cleaning gh-pages directory..."
rm_rf FileList[File.join(GH_PAGES_DIR, "**", "*")]
puts "Copying site to gh-pages branch..."
cp_r FileList[File.join("site", "*"), ".gitignore"], GH_PAGES_DIR
puts "Committing and pushing to GitHub Pages..."
sha = `git log`.match(/[a-z0-9]{40}/)[0]
Dir.chdir GH_PAGES_DIR do
sh "git add ."
sh "git commit --allow-empty -m 'Updating to #{sha}.'"
sh "git push origin gh-pages"
end
puts 'Done.'
end
end