-
Notifications
You must be signed in to change notification settings - Fork 96
/
rakefile
136 lines (102 loc) · 3.55 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
require 'yaml'
require 'tmpdir'
require 'fileutils'
# Change your GitHub reponame
GITHUB_REPONAME = "tumblr/colossus"
GITHUB_URL = "https://tumblr.github.io"
namespace :site do
task :publish do
config = YAML::load(File.open('docs.yml'))
tags = config['tags']
pwd = Dir.pwd
tmp_dir = Dir.mktmpdir("colossus")
puts "Temporary directory created at #{tmp_dir}"
Dir.chdir tmp_dir
target_dir = "#{tmp_dir}/target"
Dir.mkdir(target_dir)
puts "Setting up git repo"
system "git clone https://github.com/#{GITHUB_REPONAME}.git"
Dir.chdir "colossus"
navigation_dir = "colossus-docs/src/main/paradox/_template"
Dir.mkdir navigation_dir unless File.exists?(navigation_dir)
puts "Creating navigation file"
navigation_content_part1 = <<-RAW
<div class="nav-home">
<select>
RAW
navigation_content_part2 = <<-RAW
</select>
<script type="text/javascript">
var selects = document.getElementsByTagName('select');
for(var z=0; z<selects.length; z++) {
selects[z].value = "$page.properties.("project.version.short")$";
selects[z].onchange = function() {
var newVersion = this.value
var current = window.location.href
var next = current.replace(/$page.properties.("project.version.short")$/, newVersion)
window.location = next
};
}
</script>
</div>
$groups()$
<div class="nav-toc">
$page.navigation$
</div>
RAW
File.open("#{navigation_dir}/navigation.st", 'w') {|f|
f.write(navigation_content_part1)
tags.each { |tag|
f.write("<option value=\"#{tag}\">#{tag}</option>")
}
f.write(navigation_content_part2)
}
tags.each { |tag|
puts "Compiling docs for version #{tag}"
system "git checkout tags/v#{tag}"
system "sbt \";clean; project colossus-docs; paradox\""
version_dir = "#{target_dir}/#{tag}"
puts "Creating target version directory #{version_dir}"
Dir.mkdir version_dir
puts "Copying files to temporary directory #{version_dir}"
cp_r 'colossus-docs/target/paradox/site/main/.', version_dir
}
puts "Create redirecting index.html"
url = "#{GITHUB_URL}/colossus/#{tags.first}"
redirecting_index = "#{target_dir}/index.html"
rediect_content = <<-RAW
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=#{url}">
<script type="text/javascript">
window.location.href = "#{url}"
</script>
<title>Page Redirection</title>
</head>
<body>
If you are not redirected automatically, follow this <a href='#{url}'>#{url}</a>.
</body>
</html>
RAW
File.open(redirecting_index, 'w') {|f| f.write(rediect_content) }
puts "Upload all to gh-pages"
Dir.chdir target_dir
system "git init"
system "git checkout -b update"
system "git add ."
message = "Site updated at #{Time.now.utc}"
system "git commit -m #{message.inspect}"
system "git remote add origin https://github.com/#{GITHUB_REPONAME}.git"
system "git fetch origin gh-pages"
system "git checkout gh-pages"
system "git checkout update"
system "git merge --allow-unrelated-histories -s ours gh-pages"
system "git checkout gh-pages"
system "git merge --allow-unrelated-histories update -m #{message.inspect}"
system "git push origin"
Dir.chdir pwd
puts "Done at #{tmp_dir}, Bye!"
end
end