{
"configPort": 5000,
- "configShowExceptions": true
+ "configShowExceptions": true,
+ "configTitle": "Saba's Site"
}
import GHC.Generics (Generic(..))
import Network.Wai.Handler.Warp (Port(..))
import qualified Data.ByteString as B
+import qualified Data.Text as T
class (Monad m) => MonadReadConfig m where
readConfigFile :: FilePath -> m B.ByteString
data ServerConfiguration = ServerConfiguration { configPort :: !Port
, configShowExceptions :: !Bool
+ , configTitle :: !T.Text
} deriving (Show, Generic)
instance FromJSON ServerConfiguration
defaultConfiguration :: ServerConfiguration
defaultConfiguration = ServerConfiguration { configPort = 5000
, configShowExceptions = False
+ , configTitle = "Default Title"
}
readConfiguration :: (MonadReadConfig m) => FilePath -> m (Either String ServerConfiguration)
import qualified Data.Text as T
import qualified Data.Text.IO as T
-htmlContainer :: (MonadDirectory m) => Maybe Theme -> Maybe BlogId -> Html a -> m (Html ())
+htmlContainer :: (MonadDirectory m, MonadReader ServerConfiguration m) => Maybe Theme -> Maybe BlogId -> Html a -> m (Html ())
htmlContainer theme maybeBlogId contents = do
nav <- navigation theme
themeConfig <- themeConfiguration theme maybeBlogId
+ title <- siteTitle
pure $ sanitizeHtml $ void $ with doctypehtml_ [lang_ "en"] $ do
head_ $ do
- title_ $ toHtml siteTitle
+ title_ $ toHtml title
meta_ [charset_ "utf8"]
meta_ [name_ "description", content_ "A personal website with custom theming"]
meta_ [name_ "viewport", content_ "width=device-width, initial-scale=1.0"]
if showExceptions then p_ $ toHtml $ T.pack $ show exceptionReason else pure ()
throwError $ err404 { errBody = renderBS body }
-siteTitle :: T.Text
-siteTitle = "Saba's Site"
+siteTitle :: (MonadReader ServerConfiguration m) => m T.Text
+siteTitle = ask >>= pure . configTitle
staticPath :: FilePath
staticPath = "static"