public
Created

Completed blog file

  • Download Gist
main.rb
Ruby
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
require 'sinatra'
require 'find'
require 'rdiscount'
 
 
def get_files(path)
dir_list_array = Array.new
Find.find(path) do |f|
dir_list_array << File.basename(f, ".*") if !File.directory?(f)
end
return dir_list_array
end
 
helpers do
def formatter(page)
formatted = ""
formatted = page.gsub(/[-]/, ' ').capitalize
return formatted
end
end
 
get '/' do
@arr = get_files('./views/posts/')
erb :index
end
 
get '/view/:link' do
halt 404 unless File.exist?("views/posts/#{params[:link]}.md")
markdown :"posts/#{params[:link]}", :layout_engine => :erb
end
 
get '/about' do
#if you don't want to use Markdown for pages, do this:
#erb :"pages/about"
#Then create about.erb in views/pages
 
markdown :"pages/about", :layout_engine => :erb
end
 
not_found do
erb :missing
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.