-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docs.rb
executable file
·75 lines (68 loc) · 1.89 KB
/
build_docs.rb
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
#!/usr/bin/env ruby
require 'find'
unless system("cargo", "doc", "--no-deps", "--bin", "empowerd")
puts "Building docs failed!"
exit 1
end
bad_files = [
"constant.BRANCHES.html",
"constant.COUNT.html",
"static.LOC.html",
"static.RS.html",
]
Find.find("#{__dir__}/target/doc") do |path|
next unless File.file? path
next File.delete(path) if bad_files.include? File.basename(path)
ext = File.extname(path)
next unless [".html", ".js"].include? ext
content = File.read(path)
if ext == ".html"
content.gsub! %r{
<li>\s*
<a\s+href="(?:[a-zA-Z0-9_]+?/)*?static\.(?:LOC|RS)\.html">
(?:[a-zA-Z0-9_]+?::)*?(?:LOC|RS)
</a>\s*
</li>
}x, ""
content.gsub! %r{
<li>\s*
<a\s+href="(?:[a-zA-Z0-9_]+?/)*?constant\.(?:COUNT|BRANCHES)\.html">
(?:[a-zA-Z0-9_]+?::)*?(?:COUNT|BRANCHES)
</a>\s*
</li>
}x, ""
content.gsub! %r{
<li>\s*
<div\s+class="item-name">\s*
<a\s+class="static"\s+href="static\.(?:LOC|RS)\.html"\s+
title="static\s+(?:[a-zA-Z0-9_]+?::)*?(?:LOC|RS)">
(?:LOC|RS)
</a>\s*
<span\s+title="Restricted\s+Visibility"> 🔒</span>\s*
</div>\s*
</li>
}x, ""
content.gsub! %r{
<li>\s*
<div\s+class="item-name">\s*
<a\s+class="constant"\s+href="constant\.(?:COUNT|BRANCHES)\.html"\s+
title="constant\s+(?:[a-zA-Z0-9_]+?::)*?(?:COUNT|BRANCHES)">
(?:COUNT|BRANCHES)
</a>\s*
<span\s+title="Restricted\s+Visibility"> 🔒</span>\s*
</div>\s*
</li>
}x, ""
elsif ext == ".js"
content.gsub! %r{
"static:"\["LOC","RS"\],
}x, ""
content.gsub! %r{
"constant":\[(?:"BRANCHES")?,?(?:"COUNT")?\],
}x, ""
content.gsub! %r{
"(?:LOC|RS|COUNT|BRANCHES)",
}x, ""
end
File.write(path, content)
end