-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.rb
More file actions
74 lines (61 loc) · 1.83 KB
/
Copy pathroutes.rb
File metadata and controls
74 lines (61 loc) · 1.83 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
include JADOF
# custom markdown/redcarpet/albino formatter
Post.formatters['redcarpet'] = lambda do |text|
require "redcarpet"
require "albino"
class AlbinoHTML < Redcarpet::Render::HTML
def block_code(code,language)
Albino.colorize(code,language)
end
end
options = {:hard_wrap => true, :autolink => true, :lax_html_block => true, :no_intra_emphasis => true, :fenced_code_blocks => true, :strikethrough => true, :superscript => true}
markdown = Redcarpet::Markdown.new(AlbinoHTML, options)
markdown.render(text)
end
Post.dir = "posts"
POST_PAGES = Post.all.pages(settings.per_page)
# Routes
get "/" do
@posts = Post.all.sort{|a,b| a.date <=> b.date}.reverse.to_a.paginate(get_page,settings.per_page)
erb :index
end
get "/archive" do
@archive = Post.all.sort{|a,b| a.date <=> b.date}.reverse.group_by{|p| p.date.strftime("%B %Y")}
erb :archive
end
get "/feed.xml" do
@posts = Post.all.sort{|a,b| a.date <=> b.date}.reverse.take(10)
content_type 'application/rss+xml'
erb :feed, :layout => false
end
get "/tags/:tag" do
@title = "Tagged as '#{params[:tag]}'"
@posts = Post.all.select{|p| p.tags.to_a.include? (params[:tag].downcase) }.sort{|a,b| a.date <=> b.date}.reverse
erb :tags
end
get "/contact" do
@title = "Contact Me"
erb :contact
end
get "/search" do
term = params[:q] || ""
@title = "Search results for '#{term}'"
@posts = Post.all.select{|p| p.to_html.downcase.include_many?(term.downcase.split)}.sort{|a,b| a.date <=> b.date}.reverse
erb :search
end
get "/:post" do
@post = Post.get(params[:post])
unless @post.nil?
@title = @post.title
erb :post, :cache => false
else
not_found
end
end
# Pull latest commit from GitHub automatically
post "/pull" do
system "git pull && bundle && rm -r /public/cache/* && touch tmp/restart.txt"
end
not_found do
erb :'404'
end