blob: b24c822c6f26ff6f88f2b16ff675d2d096d56567 (
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
|
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Data.Maybe (fromMaybe)
import Data.ByteString.Lazy (ByteString)
import Data.Text.Lazy (Text)
import Data.Text.Lazy.Encoding (encodeUtf8)
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)
render :: Html -> ActionM ()
render = html . renderHtml
css :: ByteString -> ActionM ()
css src = setHeader "content-type" "text/css" >> raw src
main :: IO ()
main = do
port <- read <$> fromMaybe "3000" <$> lookupEnv "PORT" :: IO Int
scotty port routes
routes = do
get "/" $ render homepage
get "/custom.css" $ css stylesheet
displayPerson :: Person -> Markup
displayPerson person = [shamlet|
<div .card>
<img .card-img .img-fluid src=#{_pic person}>
<div .card-body>
<h4 .card-title>
#{_name person}
<h6>
<a target=_blank href="https://twitter.com/#{_twitter person}" class="fab fa-twitter">
<a target=_blank href=#{_website person} class="fas fa-globe">
<p .card-text>
<ul>
$forall book <- (_books person)
<li>
<a target=_blank .text-dark href="https://www.amazon.com/dp/#{_amznref book}">
#{_title book}
|]
title, subtitle :: Text
title = "Influenced by books"
subtitle = "Influential people and the books that made them."
homepage :: Markup
homepage = [shamlet|
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.7.1/css/all.css"
integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
crossorigin="anonymous">
<link href="/custom.css" rel="stylesheet">
<title>#{title} | #{subtitle}
<body>
<div .container.mt-5>
<div .jumbotron>
<h1 .display-4>
#{title}
<p .lead>
#{subtitle}
<p .lead>
<a href="http://eepurl.com/ghBFjv">
Get new book recommendations from the world's influencers in your email.
<div .card-columns>
$forall person <- allPeople
#{displayPerson person}
|]
stylesheet :: ByteString
stylesheet = encodeUtf8 . renderCss $ [lucius|
.jumbotron
{ background: #fff
; text-align: center
}
|] undefined
|