-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.rb
162 lines (131 loc) · 4.21 KB
/
config.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
require 'open-uri'
class Middleman::Util::EnhancedHash
# Mila: Looked into Hashie::Mash's source code where this class is
# defined (Middleman merely mixes it in). disable_warnings is the
# advertised way to turn off key conflict warnings which we probably
# cannot avoid in this project -- each package we host includes a file
# named index.json which is treated as a property. This in turn
# conflicts with Ruby's builtin [] (Array#index) method
disable_warnings
end
ignore 'www.getdbt.com/'
ignore 'source/img'
set :js_dir, 'javascripts'
set :images_dir, 'img'
activate :directory_indexes
activate :autoprefixer do |prefix|
prefix.browsers = "last 2 versions"
end
def strip_leading_v(version)
if version.start_with?("v")
version[1..-1]
else
version
end
end
def _build_package(package, org, name)
entry = package['index'].clone
versions = package['versions']
new_versions = {}
versions.each do |version_num, version_data|
version_num = strip_leading_v(version_num)
version_data['version'] = strip_leading_v(version_data['version'])
new_versions[version_num] = version_data
end
entry['versions'] = new_versions
entry
end
def combine_packages(packages)
package_map = {}
packages.each do |org, org_packages|
org_packages.each do |name, package|
entry = _build_package(package, org, name)
qualified_name = "#{org}/#{name}"
package_map[qualified_name] = entry
end
end
package_map
end
set :package_index, combine_packages(@app.data.packages)
after_configuration do
proxy "/api/v1/packages.json",
'/api/v1/raw.json',
:content_type => 'application/json',
:locals => {
:json_data => @package_index
}
packages = combine_packages(@app.data.packages)
packages.each do |package_name, package|
proxy "/#{package_name}/latest/index.html",
'/package.template.html',
:content_type => 'text/html',
:layout => 'layout',
:locals => {
:package => package,
:version => package.versions[package.latest]
}
proxy "/#{package.namespace}/index.html",
'/author.template.html',
:content_type => 'text/html',
:layout => 'layout',
:locals => {
:author => package.namespace
}
proxy "/api/v1/#{package_name}.json",
'/api/v1/package.template.json',
:content_type => 'application/json',
:locals => {
:package => package
}
redirect "#{package_name}/index.html", to: "/#{package_name}/latest/index.html"
package.versions.each do |version, package_version|
proxy "#{package_name}/#{version}/index.html",
"/package.template.html",
:layout => "layout",
:content_type => 'text/html',
:locals => {
:package => package,
:version => package_version
}
proxy "/api/v1/#{package_name}/#{version}.json",
'/api/v1/raw.json',
:content_type => 'application/json',
:locals => {
:json_data => package_version
}
end
end
end
set :protocol, 'https://'
set :host, 'hub.getdbt.com'
set :port, 443
helpers do
def host_with_port
[config[:host], optional_port].compact.join(':')
end
def optional_port
config[:port] unless [80, 443].include? config[:port].to_i
end
def site_url
config[:protocol] + host_with_port
end
def is_hidden(package, version)
@app.data.blocklist.organizations.include?(package.namespace) or @app.data.blocklist.packages.include?(package.namespace + "/" + package.name)
end
def is_latest(package, version)
package.latest == version['version']
end
def is_valid_github_url(url)
url.split("/tree/").length == 2 && url.split("/").length >= 5
end
end
ignore '/package.template.html.erb'
ignore '/author.template.html.erb'
ignore '/api/v1/package.template.json.erb'
ignore '/api/v1/raw.json.erb'
activate :livereload
configure :development do
set :host, '127.0.0.1'
set :port, 35729
set :protocol, 'http://'
end