-
Notifications
You must be signed in to change notification settings - Fork 1
/
pbui.rb
43 lines (35 loc) · 862 Bytes
/
pbui.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
# frozen_string_literal: true
require 'sinatra'
require 'redcarpet'
set :port, 7284
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
get '/' do
erb :index
end
get '/about' do
erb :about
end
get '/posts' do
post_list = Dir['public/posts/*']
erb :posts, locals: { posts: post_list }
end
get '/public/posts/:post' do
post_path = "public/posts/#{params['post']}"
post_data = File.read(post_path)
post_data.slice!(/.*\n/)
erb :post, locals: { text: markdown(post_data)}
end
get '/logs' do
log_days = Dir['public/logs/*']
erb :logs, locals: {logs: log_days}
end
get '/public/logs/:log' do
log_path = "public/logs/#{params['log']}"
log_data = File.read(log_path)
log_data.gsub! '<', '<'
log_data.gsub! '>', '>'
erb :log, locals: {text: log_data}
end
not_found do
erb :notfound
end