From b116a9ddc16744ad6ff7021cadf24bd60849433b Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 19 Feb 2019 14:37:42 -0800 Subject: Shuffle people on front page --- ibb/Main.hs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'ibb/Main.hs') diff --git a/ibb/Main.hs b/ibb/Main.hs index b24c822..4940396 100644 --- a/ibb/Main.hs +++ b/ibb/Main.hs @@ -3,18 +3,21 @@ module Main where -import Data.Maybe (fromMaybe) +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, scotty, get, html, raw, setHeader) -import Influencers -import System.Environment (lookupEnv) +import Web.Scotty (ActionM, ScottyM, scotty, get, html, raw, setHeader) render :: Html -> ActionM () render = html . renderHtml @@ -27,11 +30,14 @@ main = do port <- read <$> fromMaybe "3000" <$> lookupEnv "PORT" :: IO Int scotty port routes +routes :: ScottyM () routes = do - get "/" $ render homepage + 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|
@@ -51,11 +57,11 @@ displayPerson person = [shamlet| |] title, subtitle :: Text -title = "Influenced by books" +title = "Influenced By Books" subtitle = "Influential people and the books that made them." -homepage :: Markup -homepage = [shamlet| +homepage :: [Person] -> Markup +homepage peopleList = [shamlet| @@ -83,7 +89,7 @@ homepage = [shamlet| Get new book recommendations from the world's influencers in your email.
- $forall person <- allPeople + $forall person <- peopleList #{displayPerson person} |] @@ -93,4 +99,7 @@ stylesheet = encodeUtf8 . renderCss $ [lucius| { background: #fff ; text-align: center } +h1.display-4 +{ font-family: 'Times New Roman', times, serif +} |] undefined -- cgit v1.2.3