-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
64 lines (51 loc) · 1.63 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
64
require "sinatra"
require "haml"
require "json"
require "animalcracker"
require "seota"
module Seota
class App < Sinatra::Base
#
# Asset stuff. Do I move this to it's own app?
register AnimalCracker::Server
get_assets "/assets"
configure do
asset_path = File.join(File.dirname(__FILE__), "assets")
AnimalCracker::AssetHost.configure("asset_path" => asset_path)
end
#
# Main stuff
set :root, File.dirname(__FILE__)
# enable :dump_errors
enable :static
before do
content_type 'application/json', :charset => 'utf-8'
end
error UnusableResource do
status 427
{:error => request.env['sinatra.error'].message}.to_json
end
get("/") do
content_type 'text/html', :charset => 'utf-8'
haml(:index)
end
get %r{^/analyze/([\w.-]+)/sitemap/(.*)$} do |domain, url|
sitemap = Sitemap.new(url)
{:pages => sitemap.page_urls}.to_json
end
get %r{^/analyze/([\w.-]+)/page/(.*)$} do |domain, url|
page = Page.new(url)
{:uri => page.uri, :valid => page.valid?,
:title => {:value => page.title, :failures => page.failures_on(:title)},
:description => {:value => page.description, :failures => page.failures_on(:description)},
:keywords => {:value => page.keywords, :failures => page.failures_on(:keywords)},
:single_word_density => page.single_word_density,
:double_word_density => page.double_word_density
}.to_json
end
get %r{^/analyze/([\w.-]+)$} do |domain|
site = Site.new("http://#{domain}")
{:sitemaps => site.sitemaps.map(&:url)}.to_json
end
end # App
end