summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2019-02-19 14:37:42 -0800
committerBen Sima <ben@bsima.me>2019-02-19 14:37:42 -0800
commitb116a9ddc16744ad6ff7021cadf24bd60849433b (patch)
tree2f1426bc229452105841104fd41d7bc5eed38409
parent69df12ffb375067998a77e4d4ab22066edd942de (diff)
Shuffle people on front page
-rw-r--r--ibb/Influencers.hs2
-rw-r--r--ibb/Main.hs29
-rw-r--r--ibb/ibb.cabal8
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|
<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
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