panda-0.0.0.4.2: Panda/Config/Global.hs
module Panda.Config.Global where
import Panda.Helper.Env
import Prelude hiding ((.), (/), id)
import System.IO.UTF8 as UIO
db_id = "db"
flat_id = "."
blog_id = "blog"
config_id = "config"
tag_id = "tag"
db_uri = db_id
flat_uri = db_uri / flat_id
config_uri = flat_uri / config_id / "site.txt"
blog_uri = flat_uri / blog_id
tag_uri = flat_uri / tag_id
markup = markdown
-- unsafe, must restart server after changing config file, sorry about that ...
-- but these configs are read only, and keep the view pure, so no monad headaches involved.
user_config = UIO.readFile config_uri .purify .filter_comment .lines .map strip .map (split "\\s*=\\s*") .map tuple2
config_for' s d = user_config.lookup s .fromMaybe d
config_for s = config_for' s s
blog_title = config_for "blog_title"
blog_subtitle = config_for "blog_subtitle"
host_name = config_for "host_name"
author_email = config_for "author_email"
per_page = config_for' "per_page" "7" .read :: Int
navigation = config_for' "navigation" "About" .split "," .map strip .reject null .("Home" :)
panda_url = "http://github.com/nfjinjing/panda"