From f75eaf7fff963b88e412d315d0fdef8151943c20 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 23 Feb 2019 19:46:09 -0800 Subject: Reorganize directory --- apex/Main.hs | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 apex/Main.hs (limited to 'apex/Main.hs') diff --git a/apex/Main.hs b/apex/Main.hs new file mode 100644 index 0000000..27506d8 --- /dev/null +++ b/apex/Main.hs @@ -0,0 +1,117 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + +module Main where + +import Control.Monad.IO.Class (liftIO) +import Data.ByteString.Lazy (ByteString) +import Data.Maybe (fromMaybe) +import Data.Text.Lazy (Text) +import Data.Text.Lazy.Encoding (encodeUtf8) +import Influencers (Person(..), Book(..), allPeople) +import System.Environment (lookupEnv) +import System.Random (newStdGen) +import System.Random.Shuffle (shuffle') +import Text.Blaze (Markup) +import Text.Blaze.Html (Html) +import Text.Blaze.Html.Renderer.Text (renderHtml) +import Text.Hamlet (shamlet) +import Text.Lucius (lucius, renderCss) +import Web.Scotty (ActionM, ScottyM, scotty, get, html, raw, setHeader) + +render :: Html -> ActionM () +render = html . renderHtml + +css :: ByteString -> ActionM () +css src = setHeader "content-type" "text/css" >> raw src + +main :: IO () +main = do + port <- read <$> fromMaybe "3000" <$> lookupEnv "PORT" :: IO Int + scotty port routes + +routes :: ScottyM () +routes = do + get "/" $ do + r <- liftIO newStdGen + let peopleList = shuffle' allPeople (length allPeople) r + render (homepage peopleList) + get "/custom.css" $ css stylesheet + +displayPerson :: Person -> Markup +displayPerson person = [shamlet| +
+ +
+

+ #{_name person} +

+ + +

+