muon-0.1.0.3: src/Site.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Site (Site, readSite) where
import qualified Data.Text as T
import Data.Typeable
import Data.Data
import Data.ConfigFile
import Data.Either.Utils
data Site = Site { title :: T.Text
, style :: T.Text
, author :: T.Text
, tagline :: T.Text
} deriving (Data, Typeable, Show)
defaultSite = Site { title = "Default Blog"
, style = "/style.css"
, author = "Your Name"
, tagline = "Description of this blog"
}
getSetting :: ConfigParser -> String -> T.Text
getSetting cp s = T.pack $ forceEither $ get cp "site" s
readSite :: IO Site
readSite = do
r <- readfile emptyCP "config.ini"
let cp = forceEither r
return $ Site { title = getSetting cp "title"
, style = getSetting cp "style"
, author = getSetting cp "author"
, tagline = getSetting cp "tagline"
}