This repository was archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
131 lines (102 loc) · 2.95 KB
/
Rakefile
File metadata and controls
131 lines (102 loc) · 2.95 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
$:.unshift("#{ENV['VENDOR']}/jekyll/lib") if ENV['VENDOR']
require 'benchmark'
require 'jekyll'
BASE = File.expand_path('..', __FILE__)
CONF = File.join(BASE, '_config')
SITE = File.join(BASE, '_site')
ENVS = Dir[File.join(CONF, '*.yml')].map { |file| File.basename(file, '.yml') }
task :default => [:setup, :build]
desc "Set up build environment"
task :setup do
unless File.exist?(local = File.join(CONF, 'local.yml'))
if ENVS.include?(env = ENV['JEKYLL_ENV'])
ln_s env + '.yml', local
else
cp local + '.sample', local
end
end
end
desc "Build the site"
task :build do
warn 'Elapsed: %dm%.2fs' % Benchmark.realtime { build }.divmod(60)
end
desc "Build preview for start page with NUM's (yyyy/ww) image series"
task :series_preview do
case num = ENV['NUM'] || Date.today.strftime('%G/%V')
when /\A\d{4}\/\d{2}\z/
# ok
when /\A(\d{2})\/(\d{4})\z/
num = "#{$2}/#{$1}"
else
abort "illegal value: #{num}"
end
abort "image series not found: #{num}" if Dir[File.join(BASE, 'series', num, 'index.*')].empty?
mkdir_p src = site_path('src')
inc, exc = %w[_* index.* .htaccess images inc javascripts stylesheets],
%w[_posts _site*]
# copy required files to temp location
Dir.chdir(BASE) {
cp_r FileList.new(*inc) { |fl| fl.exclude(*exc) }, src
%W[files/images files/icons series/#{num}].each { |path|
mkdir_p target = File.join(src, File.dirname(path))
cp_r path, target
}
}
# replace ${DATE_LOCAL} in 'set var="current_series"'
# (in _layouts/default.html) with supplied YEAR/WEEK
File.open(File.join(src, '_layouts', 'default.html'), 'r+') { |f|
content = f.read.sub('${DATE_LOCAL}', num)
f.truncate(0)
f.rewind
f.print content
}
# run jekyll with <temp location> <dest location>
build(src)
end
desc "Remove current site"
task :clean do
rm_rf site_paths
end
desc "Tag release"
task :tag do
sh 'git', 'tag', "cl-#{Time.now.to_f}"
end
ENVS.each { |env|
desc "Run following tasks in #{env} environment"
task env do
ENV['JEKYLL_ENV'] = env
end
}
def site_paths
[nil, 'tmp', 'old'].map { |ext| site_path(ext) }
end
def site_path(ext = nil)
"#{SITE}#{'.' if ext}#{ext}"
end
def build(src = nil)
site, tmp, old = site_paths
options = { 'destination' => tmp }
options['source'] = src if src
profile { Jekyll::Site.new(Jekyll.configuration(options)).process }
mv site, old if File.exist?(site)
mv tmp, site
ensure
[old, src].each { |dir| rm_rf dir if dir }
end
def profile
return yield unless dir = ENV['PROFILE_JEKYLL']
require 'ruby-prof'
result, base = RubyProf.profile { yield },
File.join(BASE, dir, "prof-#{Time.now.to_i}")
{
:txt => :FlatPrinter,
:lines => :FlatPrinterWithLineNumbers,
:html => :GraphHtmlPrinter,
:stack => :CallStackPrinter
}.each { |ext, name|
File.open("#{base}.#{ext}", 'w') { |f|
RubyProf.const_get(name).new(result).print(f)
}
}
warn "Profile: #{base}"
end