diff options
author | Ben Sima <ben@bsima.me> | 2019-02-19 14:37:42 -0800 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-02-19 14:37:42 -0800 |
commit | b116a9ddc16744ad6ff7021cadf24bd60849433b (patch) | |
tree | 2f1426bc229452105841104fd41d7bc5eed38409 /ibb/Main.hs | |
parent | 69df12ffb375067998a77e4d4ab22066edd942de (diff) |
Shuffle people on front page
Diffstat (limited to 'ibb/Main.hs')
-rw-r--r-- | ibb/Main.hs | 29 |
1 files changed, 19 insertions, 10 deletions
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| <div .card> @@ -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| <!doctype html> <head> <meta charset="utf-8"> @@ -83,7 +89,7 @@ homepage = [shamlet| Get new book recommendations from the world's influencers in your email. <div .card-columns> - $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 |