diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..fd1e076 --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,67 @@ +{-# 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 |