-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
61 lines (53 loc) · 1.48 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
desc "render content to a single html file"
task :generate => :environments do
head = File.read('head.part')
tail = File.read('tail.part')
markdown = File.read 'index.md'
content = @markdown.render markdown
File.open('all.html', 'w') do |f|
f.write head
f.write content[10..-1]
f.write tail
end
cleaned_markdown = markdown
.split(/\n/)
.select{|s| s !~ /^`!/}
.map{|s| s.gsub /`![^`]+`/,''}
.join("\n")
content = @markdown.render cleaned_markdown
File.open('index.html', 'w') do |f|
f.write head
f.write content[10..-1]
f.write tail
end
end
desc "package content with resource files"
task :pkg => :generate do
sources = File.readlines('index.html').map do |line|
if line.chomp =~ /<link.+href=\"(.+)\">/
$1
elsif line.chomp =~ /<script.+src=\"(.+)\".+>/
$1
elsif line.chomp =~ /<img src=\"([^"]+)\".+>/
$1
end
end.uniq.compact
sources << 'index.html'
require 'zip/zip'
branch_name = `git branch`.split(/\n/).select{|s| s =~ /^\*/ }[0][2..-1]
file = "#{branch_name || 'slide'}.zip"
puts file
File.delete file rescue nil
Zip::ZipFile.open(file, Zip::ZipFile::CREATE) do |zipfile|
sources.each do |filename|
if filename =~ /^\.\//
filename = filename[2..-1]
end
puts "source: #{filename}"
zipfile.add(filename, filename)
end
end
end
task :environments do
require './lib/boot.rb'
end