summaryrefslogtreecommitdiff
path: root/ibb/Main.hs
blob: 91112f095b939437980a28ad53c26eb7ce6532b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}

module Main where

import Data.Function ((&))
import Data.Text (Text)
import Web.Scotty (ActionM, scotty, get, html)
import Text.Blaze.Html.Renderer.Text (renderHtml)
import Text.Hamlet (shamlet, hamlet)
import Text.Blaze.Html (Html)
import Text.Blaze (Markup)
import Data.Monoid (mconcat)

render :: Html -> ActionM ()
render = html . renderHtml

main :: IO ()
main = scotty 3000 $
    get "/" $ render homepage

data Person = Person
  { _name :: Text
  , _pic :: Text
  , _twitter :: Text
  , _website :: Text
  , _books :: [Book]
  }

data Book = Book
  { _title :: Text
  , _author :: Text
  , _link :: Text
  }


allPeople =
  [ Person { _name = "Joe Rogan"
           , _pic = "https://pbs.twimg.com/profile_images/552307347851210752/vrXDcTFC_400x400.jpeg"
           , _twitter = "joerogan"
           , _website = "joerogan.com"
           , _books = [ Book {_title = "Food of the Gods"
                             , _author = "Terence McKenna"
                             , _link = "https://www.amazon.com/Food-Gods-Original-Knowledge-Evolution/dp/0553371304"
                             }
                      , Book { _title = "The War of Art"
                             , _author ="Steven Pressfield"
                             , _link ="https://www.amazon.com/dp/B007A4SDCG/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1"
                             }
                      ]
           }
  , Person { _name = "Beyoncé"
           , _pic = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTxT84sF19lxdnSiblIXAp-Y4wAigpQn8sZ2GtAerIR_ApiiEJfFQ"
           , _twitter = "Beyonce"
           , _website = "beyonce.com"
           , _books = [ Book { _title = "What Will It Take To Make A Woman President?"
                            , _author = "Marianne Schnall"
                            , _link = "https://www.amazon.com/dp/B00E257Y7G/ref=dp-kindle-redirect?_encoding=UTF8&btkr="}
                      ]
           }
  , Person { _name = "Barrack Obama"
           , _pic = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQeLzftR36p0hYI-EKNa5fm7CYDuN-vyz23_R48ocqa8X1nPr6C"
           , _twitter = "BarackObama"
           , _website = "barackobama.com"
           , _books = [ Book { _title = "An American Marriage"
                             , _author = "Tayari Jones"
                             , _link = "https://www.amazon.com/American-Marriage-Novel-Oprahs-Selection-ebook/dp/B01NCUXEFR"}
                      , Book { _title = "Americanah"
                             , _author = "Chimamanda Ngozi Adichie"
                             , _link = "https://www.amazon.com/dp/B00A9ET4MC/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1"}
                      ]
           }
  , Person { _name = "Warren Buffet"
           , _pic = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQQbmnUykS6zqgzaf44tsq1RAsnHe6H7fapEoSqUwAoJGSFKbAPSw"
           , _twitter = "WarrenBuffett"
           , _website = "berkshirehathaway.com"
           , _books = [ Book { _title = "The Intelligent Investor"
                             , _author = "Benjamin Graham"
                             , _link = "https://www.amazon.com/dp/B000FC12C8/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1"}
                      , Book { _title = "Security Analysis"
                             , _author = "enjamin Graham"
                             , _link = "https://www.amazon.com/Security-Analysis-Foreword-Buffett-Editions-ebook/dp/B0037JO5J8"}
                      ]
           }
  , Person { _name = "Micheal Jordan"
           , _pic = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQfl_Dm2RUhknIxGEafGOlQC7Jj3Ky0nyQYk6GvG791sClzwFQb"
           , _twitter = ""
           , _website = "michaeljordansworld.com"
           , _books = [ Book { _title = "Statistical Inference"
                             , _author = "George Casella"
                             , _link = "https://www.amazon.com/Statistical-Inference-George-Casella/dp/0534243126"}
                      , Book { _title = "A Course In Large Sample Therapy"
                             , _author = "Thomas S. Ferguson"
                             , _link = "https://www.amazon.com/Course-Sample-Chapman-Statistical-Science/dp/041204371"}
                      ]
           }
  ]

displayPerson person = [shamlet|
<div .card .ml-3 .mb-3 style=width:22rem;>
  <img .card-img .img-fluid src=#{_pic person}>
  <h4>#{_name person}
  <ul>
    $forall book <- (_books person)
      <li><a href=#{_link book} class="text-dark">#{_title book}
|]

homepage = [shamlet|
<!doctype html>
<head>
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<body>
  <div .container>
    <div .row>
      $forall person <- allPeople
        #{displayPerson person}
|]