This repository was archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.rb
More file actions
114 lines (90 loc) · 2.43 KB
/
generate.rb
File metadata and controls
114 lines (90 loc) · 2.43 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
require 'git'
require 'fileutils'
require 'redcarpet'
def log(text)
puts "#{Time.now.utc}: #{text}"
end
log "started update"
$root = File.expand_path(File.join('..', 'www'))
Dir.mkdir($root) unless File.exists?($root)
def convert_readme
out = File.join($root, 'index.html')
inp = 'README.md'
return if File.exists?(out) and File.stat(inp).mtime < File.stat(out).mtime
log "Rendering #{inp} to #{out}"
renderer = Redcarpet::Render::HTML.new(prettify: true)
markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)
html = markdown.render(File.read(inp))
File.open(out, 'w') do |f|
f.write <<EOT
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Industrial Ontologies Foundary</title>
<style type="text/css">
body {
font-family: "Open Sans", sans-serif;
}
h1 {
border-bottom: 1px solid #c9d1d9;
margin-bottom: 14px;
padding-bottom: 0.3em;
margin-top: 24px;
line-height: 1.25;
}
</style>
</head>
<body>
EOT
f.write(html)
f.write <<EOT
</body>
</html>
EOT
end
end
log "Updating Repos"
system('git', 'pull')
system('git', 'submodule', 'update')
log "Updating ontologies"
dirs = nil
File.open('.gitmodules') do |f|
dirs = f.read.split("\n").select { |l| l =~ /path/ }.map { |l| l.split.last }
end
def extract(git, mod, version, prefix)
dir = "#{prefix}#{mod}"
log "Extracting #{mod} version #{version}"
file = git.archive(version, nil, { format: 'tar', prefix: "#{dir}/" })
list = `tar tf #{file}`.split("\n").select { |f| f =~ /\.rdf$/ }
Dir.chdir($root) do
log "Removing #{$root}/#{dir}"
FileUtils.rm_r(dir) if File.exists?(dir)
log "Extracting rdf files for #{version} to #{$root}/#{dir}/"
system('tar', 'xvf', file, *list)
end
end
dirs.each do |mod|
git = Git.open(mod)
tags = git.tags.map(&:name)
unless tags.empty?
tags.each do |tag|
prefix = "#{tag.delete('-')}/"
extract(git, mod, tag, prefix)
end
prefix = tags.sort.last.delete('-')
Dir.chdir($root) do
Dir["#{prefix}/*"].select { |d| File.directory?(d) }.each do |d|
target = "./#{File.basename(d)}"
log "Removing #{$root}/#{target}"
FileUtils.rm_r(target) if File.exists?(target)
log "linking #{$root}/#{d} to #{$root}/#{target}"
FileUtils.ln_sf(d, target)
end
end
else
extract(git, mod, 'HEAD', '')
end
end
convert_readme
log "completed update"