From 0fe906ae7453aa684e998bbcc7a78b62d84f0206 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 6 Apr 2014 22:55:16 +0200 Subject: Show resume and projects from a configuration file --- src/Main.hs | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Main.hs (limited to 'src/Main.hs') 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 -- cgit v1.2.3