This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Rakefile
136 lines (113 loc) · 3.81 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require 'rubygems'
require 'erb'
require 'maruku'
require 'yaml'
def generate_page(page_data)
page = page_data['page']
puts "generating #{page}"
@title = page_data['name']
@desc = page_data['desc']
@pcontent = ''
if s = page_data['size']
w, h = s.split('x')
else
w = '640'
h = '360'
end
# add video if present
if code = page_data['cast']
@pcontent += '<center><embed src="http://www.youtube.com/v/' + code + '?hl=en_US&version=3&rel=0'
@pcontent += '" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" '
@pcontent += 'allowscriptaccess="always" allowfullscreen="true"></embed></center>'
end
# render markdown from page, if present
mpage = "pages/#{page}.markdown"
if File.exists?(mpage)
content = File.read(mpage)
doc = Maruku.new(content)
@pcontent += doc.to_html
end
@pcontent += '<div class="page-turns">'
if (n = @nextlast[:last][page]) && (nname = @nextlast[:lastname][page])
@pcontent += "<a href=\"#{n}.html\" class=\"page-prev\">« #{nname}</a>"
end
if (n = @nextlast[:next][page]) && (nname = @nextlast[:nextname][page])
@pcontent += "<a href=\"#{n}.html\" class=\"page-next\">#{nname} »</a>"
end
@pcontent += "</div>"
pname = "p/#{page}.html"
out = ERB.new(File.read('template/page.erb.html')).result
File.open(pname, 'w') { |f| f.write(out) }
end
# generate the gitcast episode listing page
def generate_gitcasts
puts "generating screencasts"
@title = 'Git Screencasts'
@desc = ''
@pcontent = ''
@pcontent += '<div class="align-center"><iframe width="640" height="480" '
@pcontent += 'src="http://www.youtube.com/embed/Esl439M154M?rel=0" '
@pcontent += 'frameborder="0" allowfullscreen id="js-youtubed"></iframe></div>'
@pcontent += '<h2>Episode Listing</h2>'
@pcontent += '<div class="js-gitcasts">'
# render markdown from page, if present
rawpage = "pages/screencasts.md"
if File.exists?(rawpage)
content = File.read(rawpage)
doc = Maruku.new(content)
@pcontent += doc.to_html
end
@pcontent += '</div>'
@pcontent += '<script src="../js/jquery-1.2.6.pack.js"></script>'
@pcontent += '<script src="../js/gitcasts.js"></script>'
pname = "screencasts.html"
out = ERB.new(File.read('template/page.erb.html')).result
File.open(pname, 'w') { |f| f.write(out) }
end
# generate the site
desc "Generate the html files for the site"
task :gensite do
ep = YAML::load( File.open('episodes.yaml') )
@content = ''
# finding the next and last pages
last = lastname = nil
@nextlast = {:last => {}, :lastname => {}, :next => {}, :nextname => {}}
ep['episodes'].each do |section|
section['values'].each do |episode|
if (p = episode['page']) && (pname = episode['name'])
@nextlast[:last][p] = last
@nextlast[:lastname][p] = lastname
@nextlast[:next][last] = p
@nextlast[:nextname][last] = pname
last = p
lastname = pname
end
end
end
ep['episodes'].each do |section|
counter = 0
@content += '<div class="episode-list">'
@content += "<h2>" + section['section'] + "</h2>"
section['values'].each do |episode|
counter += 1
if ((counter % 6) == 0)
@content += "<div class='episode last'>"
else
@content += "<div class='episode'>"
end
if episode['page']
@content += "<h4><a href=\"p/" + episode['page'] + ".html\">" + episode['name'] + "</a></h4>"
generate_page(episode)
else
@content += '<h4>' + episode['name'] + '</h4>'
end
@content += '<p>' + episode['desc'] + '</p>'
@content += "</div>"
end
@content += "</div>"
end
out = ERB.new(File.read('template/index.erb.html')).result
File.open('index.html', 'w') { |f| f.write(out) }
generate_gitcasts
end
task :default => [:gensite]