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/Influencers.hs | 2 +- ibb/Main.hs | 29 +++++++++++++++++++---------- ibb/ibb.cabal | 8 +++++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ibb/Influencers.hs b/ibb/Influencers.hs index 67907f8..7a7031f 100644 --- a/ibb/Influencers.hs +++ b/ibb/Influencers.hs @@ -3,7 +3,7 @@ module Influencers where -import Data.Text.Lazy(Text) +import Data.Text.Lazy (Text) data Person = Person { _name :: Text 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 diff --git a/ibb/ibb.cabal b/ibb/ibb.cabal index e54e3d4..4d8ebc7 100644 --- a/ibb/ibb.cabal +++ b/ibb/ibb.cabal @@ -19,10 +19,12 @@ executable ibb Influencers build-depends: base >= 4.6 && < 5 - , scotty - , shakespeare , blaze-html , blaze-markup - , text , bytestring + , random + , random-shuffle + , scotty + , shakespeare + , text default-language: Haskell2010 -- cgit v1.2.3