This repository was archived by the owner on Feb 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
89 lines (82 loc) · 2.66 KB
/
app.rb
File metadata and controls
89 lines (82 loc) · 2.66 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
require 'open-uri'
require 'sinatra/config_file'
set :haml, :format => :html5
config_file "site-config.yaml"
helpers do
def render(*args)
if args.first.is_a?(Hash) && args.first.keys.include?(:partial)
return haml "#{args.first[:partial]}".to_sym, :layout => false
else
super
end
end
def construct_title(page_title="")
if page_title.empty?
title = settings.base_title
else
title = "#{page_title} #{settings.title_seperator} #{settings.base_title}"
end
return title
end
def show_post_navigation(previous_name="Older", next_name="Newer")
nav_string = "<nav id='post-navigation' class='cf'>"
if @post_meta[:previous] != ""
nav_string.concat("<div id='previous-navigation'><a href='"+@post_meta[:previous]+"'>"+ previous_name + "</a></div>")
end
if @post_meta[:next] != ""
nav_string.concat("<div id='next-navigation'><a href='"+@post_meta[:next]+"'>"+ next_name +"</a></div>")
end
return nav_string.concat("</nav>")
end
def show_post_date(format="%d/%m/%Y", post_meta=@post_meta)
return Time.parse(post_meta[:date]).strftime(format)
end
def show_latest_commit
feed = open('https://github.com/ajclarkson/frankly/commits/master.atom') {|f| f.read }
items = parse feed
item = items.first
return item[:title]
end
def parse feed
doc = Nokogiri::XML feed
doc.search('entry').map do |doc_entry|
entry = { }
entry[:title] = doc_entry.at('title').text
entry
end
end
end
get "/" do
@page_content = RDiscount.new(File.open("pages/index.md").read).to_html
@title = construct_title()
haml :page
end
get "/blog" do
@posts = YAML::load(File.open("_post-index.yaml"))
@title = construct_title("Archive")
haml :blog
end
get "/rss.xml" do
@posts = YAML::load(File.open("_post-index.yaml"))
builder :rss
end
get "/:page" do
pages = YAML::load(File.open"_page-index.yaml")
@page_meta = pages.find{|x| x[:slug] == "/#{params[:page]}"}
page_file_contents = File.read("pages/#{@page_meta[:filename]}.md")
markdown = page_file_contents.match(/^(?<headers>---\s*\n.*?\n?)^(---\s*$\n?)/m)
@page_title = @page_meta[:title]
@page_content = RDiscount.new(markdown.post_match).to_html
@title = construct_title(@page_title)
haml :page
end
get "/blog/:post" do
posts = YAML::load(File.open"_post-index.yaml")
@post_meta = posts.find{|x| x[:slug] == "/blog/"+params[:post]}
post_file_contents = File.read("posts/"+@post_meta[:filename]+".md")
markdown = post_file_contents.match(/^(?<headers>---\s*\n.*?\n?)^(---\s*$\n?)/m)
@post_title = @post_meta[:title]
@post_content = RDiscount.new(markdown.post_match).to_html
@title = construct_title(@post_title)
haml :post
end