-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
192 lines (176 loc) · 5.46 KB
/
Copy pathMain.hs
File metadata and controls
192 lines (176 loc) · 5.46 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Clay ((?), Css)
import qualified Clay as C
import Control.Monad (forM_)
import Data.Aeson (FromJSON)
import qualified Data.Aeson as Aeson
import Data.Function ((&))
import Data.Text (Text)
import Data.Time.Clock (UTCTime, getCurrentTime)
import Data.Time.Format (defaultTimeLocale, formatTime)
import Development.Shake
import Development.Shake.FilePath
import GHC.Generics (Generic)
import Lucid
import Main.Utf8
import qualified Rib
import Rib (IsRoute)
import Rib.Parser.Pandoc as Pandoc
data Route a where
IndexRoute :: Route IndexData
data IndexData
= IndexData
{ meetup :: Meetup,
events :: [Event],
currentTime :: UTCTime
}
instance IsRoute Route where
routeFile = \case
IndexRoute ->
pure "index.html"
main :: IO ()
main = withUtf8 $ do
Rib.run "src" "public" generateSite
generateSite :: Action ()
generateSite = do
Rib.buildStaticFiles [ "datenschutz.txt", "imprint.txt", "robots.txt" ]
indexData <-
IndexData
<$> readJson "meetup.json"
<*> readJson "events.json"
<*> liftIO getCurrentTime
writeHtmlRoute IndexRoute indexData
compileElmModule "Logo.elm" "logo.js"
readJson :: FromJSON a => FilePath -> Action a
readJson filePath = do
inputDir <- Rib.ribInputDir
either fail pure =<< liftIO (Aeson.eitherDecodeFileStrict' (inputDir </> filePath))
data Meetup
= Meetup
{ description :: Text
}
deriving (Generic, Show)
instance FromJSON Meetup
data Event
= Event
{ name :: Text,
local_date :: Text,
local_time :: Text,
yes_rsvp_count :: Int,
description :: Text,
link :: Text
}
deriving (Generic, Show)
instance FromJSON Event
writeHtmlRoute r = Rib.writeRoute r . Lucid.renderText . renderPage r
compileElmModule :: FilePath -> FilePath -> Action ()
compileElmModule inputFilePath outputFilePath = do
inputDir <- Rib.ribInputDir
outputDir <- Rib.ribOutputDir
command
[]
"elm"
[ "make",
"--optimize",
inputDir </> inputFilePath,
"--output",
outputDir </> outputFilePath
]
renderPage _route (IndexData {..}) = do
let asMarkdown =
Pandoc.render . Pandoc.parsePure Pandoc.readMarkdown
firstEvent =
case events of
(event : _) -> Just event
_ -> Nothing
currentDate = formatTime defaultTimeLocale "%Y-%m-%d" currentTime
doctype_
html_ [lang_ "en"] $ do
head_ $ do
title_ "Hannover Elm Language Meetup"
meta_ [charset_ "utf-8"]
meta_ [name_ "viewport", content_ "width=device-width, initial-scale=1"]
link_ [href_ "https://fonts.googleapis.com/css?family=Roboto", rel_ "stylesheet"]
style_ [type_ "text/css"] $ C.render pageStyle
body_ $ do
header_ $ do
div_ [id_ "logo"] ""
script_ [src_ "logo.js"] ("" :: Text)
script_ "Elm.Logo.init({node:document.querySelector(\"#logo\")})"
main_ $ do
section_ [class_ "section section--about"] $ do
h1_ "Hannover Elm Language Meetup"
p_ $
meetup
& (description :: Meetup -> Text)
& asMarkdown
firstEvent
& fmap
( \event ->
section_ [class_ "section section--next-event"] $ do
h2_ $ do
span_ "Next Meetup: "
small_ $ do
span_ (toHtml (local_date event))
span_ " "
span_ (toHtml (local_time event))
a_ [href_ (link event), target_ "blank"] "RSVP on Meetup"
)
& maybe (toHtml ("" :: Text)) id
forM_ (maybe [] (: []) firstEvent) $ \event ->
section_ [class_ "section section--events"] $ do
article_ [class_ "event"] $ do
h3_ $ do
span_ (toHtml (name event))
small_ $ do
span_ " "
span_ (toHtml (local_date event))
span_ " "
span_ (toHtml (local_time event))
p_ $
event
& (description :: Event -> Text)
& asMarkdown
footer_ $ do
span_ (toHtml ("last updated " ++ currentDate))
span_ ", "
a_
[href_ "https://github.com/hannover-elm/website", target_ "blank"]
"source code"
span_ ", "
a_
[href_ "/static/imprint.txt", target_ "blank", rel_ "nofollow"]
"imprint"
span_ ", "
a_
[href_ "/static/datenschutz.txt", target_ "blank", rel_ "nofollow"]
"datenschutz"
pageStyle :: Css
pageStyle = do
C.html ? do
C.fontFamily ["Roboto"] [C.sansSerif]
C.color (C.rgba 0 0 0 0.87)
C.backgroundColor (C.parse "#efefef")
C.body ? do
C.maxWidth (C.px 600)
C.backgroundColor (C.white)
C.padding (C.px 10) (C.px 10) (C.px 10) (C.px 10)
C.boxSizing C.borderBox
C.footer ? do
C.fontSize (C.rem 0.875)
C.marginTop (C.px 16)
C.fontStyle C.italic
C.header ? do
C.borderRadius (C.px 2) (C.px 2) (C.px 2) (C.px 2)
C.overflow C.hidden
C.margin (C.px (-10)) (C.px (-10)) (C.px (-10)) (C.px (-10))
"#logo" ? do
C.backgroundColor (C.parse "#ccc")