Skip to content

Instantly share code, notes, and snippets.

@andyhawthorne
Created August 27, 2012 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyhawthorne/3487531 to your computer and use it in GitHub Desktop.
Save andyhawthorne/3487531 to your computer and use it in GitHub Desktop.
Completed blog file
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment