class WebInterface < Sinatra::Base get '/' do @title = $config.title @posts = Post.all erb :index end get '/:year/:month/:day/:slug' do |y, m, d, slug| @posts = Post.where(slug: slug) date = DateTime.strptime("#{y}-#{m}-#{d}", "%Y-%m-%d") if @posts.empty? or @posts[0].created_at.to_date != date.to_date then status 404 @title = '404 Not Found' erb :not_found else @post = @posts[0] @title = @post.title erb :post end end end