44 lines
1002 B
Ruby
44 lines
1002 B
Ruby
require "sinatra/base"
|
|
require "dotenv"
|
|
require "slim"
|
|
|
|
module Blog
|
|
APP_ENV = ENV.fetch("ENV") { "development" }
|
|
LOADED_ENV = Dotenv.load(".env.#{APP_ENV}.local", ".env.local", ".env")
|
|
end
|
|
|
|
require_relative "blog/post"
|
|
require_relative "blog/cache"
|
|
require_relative "blog/config"
|
|
|
|
module Blog
|
|
class App < Sinatra::Base
|
|
CACHE = Cache.new
|
|
CONFIG = Config.load!
|
|
|
|
get "/" do
|
|
slim :index, locals: { config: CONFIG, topics: CACHE.topics.values, dates: CACHE.dates.values }
|
|
end
|
|
|
|
get "/date/:date" do
|
|
post = CACHE.find_by_date params["date"]
|
|
slim :post, locals: { config: CONFIG, post: }
|
|
end
|
|
|
|
get "/topic/:title" do
|
|
post = CACHE.find_by_topic params["title"]
|
|
slim :post, locals: { config: CONFIG, post: }
|
|
end
|
|
|
|
set :bind, ENV["APP_BIND"] || "127.0.0.1"
|
|
set :port, ENV["APP_PORT"] || "10666"
|
|
|
|
set :environment, APP_ENV
|
|
ENV["RACK_ENV"] = APP_ENV
|
|
|
|
set :public_folder, "public"
|
|
|
|
run! if app_file == $PROGRAM_NAME
|
|
end
|
|
end
|