-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp.rb
More file actions
93 lines (71 loc) · 1.55 KB
/
app.rb
File metadata and controls
93 lines (71 loc) · 1.55 KB
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
require 'rubygems'
require 'sinatra'
require 'chronic'
require 'maneki'
require 'moredown'
require 'erb'
require 'haml'
ENV['TZ'] = 'Australia/Brisbane'
require 'models'
require 'helpers'
get '/' do
if params[:page] == '1'
redirect '/'
end
@page = (params[:page] || 1).to_i
@posts = Post.page(@page) || raise(Sinatra::NotFound)
haml :index
end
get '/tags/:tag/?' do
@tag = params[:tag]
@posts = Post.find_tagged_with(@tag)
haml :tag
end
get '/archive/?' do
@posts_by_month_and_year = Post.archive
haml :archive
end
get '/rss' do
@posts = Post.page(1, 10)
content_type 'application/rss+xml'
erb :rss, :layout => false
end
get '/sitemap.xml' do
@posts = Post.all
content_type 'text/xml'
erb :sitemap, :layout => false
end
get '/media/:file.:ext' do
filename = File.dirname(__FILE__) + '/posts/media/' + params[:file] + '.' + params[:ext]
if File.file? filename
send_file(filename)
else
raise(Sinatra::NotFound)
end
end
get '/:slug.text' do
filename = File.dirname(__FILE__) + '/posts/' + params[:slug] + '.text'
if File.file? filename
content_type 'text/plain'
File.open filename
end
end
get '/:slug/?' do
@post = Post.find(params[:slug])
if @post
haml :post
else
@keyword = params[:slug].gsub('-', ' ')
@posts = Post.search(@keyword)
haml :search
end
end
before do
# Redirect to nathanhoad.net
unless request.env['REMOTE_ADDR'] == '127.0.0.1'
redirect 'http://nathanhoad.net' if request.env['HTTP_HOST'] != 'nathanhoad.net'
end
end
not_found do
haml :not_found
end