diff options
author | Joris Guyonvarch | 2014-04-06 22:55:16 +0200 |
---|---|---|
committer | Joris | 2019-05-01 15:34:22 +0200 |
commit | 0fe906ae7453aa684e998bbcc7a78b62d84f0206 (patch) | |
tree | d3968af830b964193349187fb6fc583780cd0ce3 /src/Main.hs | |
parent | 8b11c4be2b3ac354fa14534662dbd92374617a3e (diff) |
Show resume and projects from a configuration file
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 |