{-# LANGUAGE OverloadedStrings #-} module Main ( main ) where import Control.Concurrent (forkIO) import Control.Monad.IO.Class (liftIO) import Network.Wai.Middleware.Static import Web.Scotty import Data.Text.Lazy (isPrefixOf) import Data.Yaml (decodeFileEither) import Model import Model.Translation.Language import View.NotFound (renderNotFound) import View.Page (renderPage) import View.Project (renderProjects) import View.Resume (renderResume) import Design.Global (compactDesign) import qualified Conf as Conf import Date (getCurrentDate) import Daemon (runDaemon) import Resume (generateResumes) main :: IO () main = do modelOrError <- decodeFileEither "data.yaml" confOrError <- Conf.getConf "application.conf" case (modelOrError, confOrError) of (Left modelError, _) -> putStrLn $ "Model error: " ++ (show modelError) (_, Left confError) -> putStrLn $ "Configuration error: " ++ (show confError) (Right model, Right conf) -> do _ <- forkIO . runDaemon (Conf.generateResumes conf) $ \() -> generateResumes model conf scotty (Conf.port conf) $ do middleware $ staticPolicy (noDots >-> addBase "public") get "/design" $ do addHeader "Content-Type" "text/css" text compactDesign get "/" $ do language <- getLanguage currentDate <- liftIO getCurrentDate html $ renderPage model (renderResume conf language currentDate model) get "/projects" $ do language <- getLanguage html $ renderPage model (renderProjects conf language (projects model)) notFound $ do language <- getLanguage html $ renderPage model (renderNotFound language) getLanguage :: ActionM Language getLanguage = do mbLang <- header "Accept-Language" case mbLang of Just lang | "fr" `isPrefixOf` lang -> return French _ -> return English