forked from sequelize/doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
63 lines (45 loc) · 1.26 KB
/
app.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
require 'sinatra'
require 'redcarpet'
require 'net/http'
require 'uri'
require './lib/sequelize_renderer'
require './lib/helpers'
set :markdown, :renderer => SequelizeRenderer, :fenced_code_blocks => true, :strikethrough => true
def check_host(req)
uri = URI(req.url)
allowed_hosts = [/^sequelizejs.com/, /^localhost/]
unless allowed_hosts.map{ |host| !!uri.host.match(host) }.include?(true)
uri.host = 'sequelizejs.com'
redirect to(uri.to_s), 301
end
end
get '/' do
check_host(request)
redirect to('/documentation')
end
get '/documentation' do
check_host(request)
html = erb('documentation/index'.to_sym)
html = Helpers.inject_navigation(html)
html
end
get '/heroku' do
check_host(request)
html = erb('articles/heroku/index'.to_sym)
html = Helpers.inject_navigation(html)
html
end
get '/changelog' do
check_host(request)
changelog = `curl https://raw.github.com/sequelize/sequelize/master/changelog.md`
changelog = changelog.gsub('# ', '### ').scan(/(###.+?)\n\n/m)
html = erb('changelog/index'.to_sym, :locals => { :changelog => changelog })
html = Helpers.inject_navigation(html)
html
end
get '/imprint' do
check_host(request)
html = erb('imprint/index'.to_sym)
html = Helpers.inject_navigation(html)
html
end