-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.rb
95 lines (81 loc) · 2.81 KB
/
generate.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require 'nokogiri'
require 'sqlite3'
require 'json'
# Remove existing docs (if any), download latest version and move into docset
%x{
rm -rf UIKIT.docset/Contents/Resources
mkdir UIKIT.docset/Contents/Resources
wget https://github.com/uikit/uikit/archive/master.zip -O uikit-master.zip
unzip uikit-master.zip
mkdir UIKIT.docset/Contents/Resources/Documents
mv uikit-master/* UIKit.docset/Contents/Resources/Documents/
rm -rf uikit-master
rm uikit-master.zip
}
resources_path = 'UIKit.docset/Contents/Resources'
documents_path = "#{resources_path}/Documents"
# init sqlite3 db
db = SQLite3::Database.new("#{resources_path}/docSet.dsidx")
db.execute('CREATE TABLE IF NOT EXISTS searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);')
db.execute('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);')
# Guides
guides = %w{
documentation_get-started.html
documentation_how-to-customize.html
documentation_layouts.html
documentation_project-structure.html
documentation_less-sass.html
documentation_create-a-theme.html
documentation_create-a-style.html
documentation_customizer-json.html
documentation_javascript.html
components.html
addons.html
}
# Don't index these
ignore = %w{
index.html
layouts_blog.html
layouts_contact.html
layouts_documentation.html
layouts_frontpage.html
layouts_login.html
layouts_portfolio.html
layouts_post.html
customizer.html
}
docs = Dir["#{documents_path}/*.html"] + Dir["#{documents_path}/docs/*.html"]
docs.each do |doc|
# Cleanup
file = File.read(doc)
file.gsub!('<li><a href="customizer.html">Customizer</a></li>',"")
file.gsub!('<li><a href="docs/customizer.html">Customizer</a></li>',"")
file.gsub!('<li><a href="../showcase/index.html">Showcase</a></li>',"")
file.gsub!('<li><a href="showcase/index.html">Showcase</a></li>',"")
file.gsub!(' - UIkit documentation</title>',"</title>")
File.open(doc,'w'){|f|f<<file}
filename = File.basename(doc)
# don't index this file if in ignore list
unless ignore.include?(filename)
nok = Nokogiri::HTML(file)
index_title = nok.css("h1").first.text
index_path = doc.gsub("#{documents_path}/","")
if filename =~ /addons_/
index_title = "#{index_title} (Add-on)"
end
if guides.include?(filename)
# index this file as a Guide
index_type = 'Guide'
else
# index this file as a Component
index_type = 'Component'
end
# insert this file into the index
db.execute "INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ('#{index_title}', '#{index_type}', '#{index_path}');"
end
end
# tar it up
%x{tar --exclude='.DS_Store' -cvzf UIKit.tgz UIKit.docset}
# display version number
puts "Done. Use this version in the docset.json file:"
puts JSON.parse(File.read("#{documents_path}/package.json"))["version"]