-
Notifications
You must be signed in to change notification settings - Fork 6
/
GeneratePeople.hs
101 lines (83 loc) · 2.78 KB
/
GeneratePeople.hs
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
{-# LANGUAGE DeriveGeneric, OverloadedStrings #-}
module Main where
import Prelude hiding (div)
import GHC.Generics
import Data.Yaml
import qualified Data.ByteString as BS
import Html
type Markdown = String
data Status = Academic | PhDStudent | Research | PhDFinished | Alum
deriving (Show, Eq, Generic)
instance FromJSON Status where
parseJSON (String "academic") = pure Academic
parseJSON (String "phd-student") = pure PhDStudent
parseJSON (String "research") = pure Research
parseJSON (String "phd-finished") = pure PhDFinished
parseJSON (String "alum") = pure Alum
parseJSON _ = fail "invalid status"
data LinkRelationship
= HomePage
| Pure
| Thesis
| Staff
deriving (Show, Eq, Generic)
instance FromJSON LinkRelationship where
parseJSON (String "homepage") = pure HomePage
parseJSON (String "staff") = pure Staff
parseJSON (String "pure") = pure Pure
parseJSON (String "thesis") = pure Thesis
parseJSON _ = fail "invalid link type"
data Link =
Link { href :: String
, rel :: LinkRelationship
-- , linkTitle :: Maybe String
}
deriving (Show, Eq, Generic)
instance FromJSON Link
data Person = Person
{ name :: String
, ident :: Maybe String
, pronouns :: Maybe String
, title :: Maybe String
, status :: Status
, picture :: Maybe String
, email :: Maybe String
, links :: Maybe [Link]
, description :: Markdown
, phdTopics :: Maybe [Markdown] -- Only relevant for status == Academic
} deriving (Show, Eq, Generic)
instance FromJSON Person
------------------------------------------------------------------------------
linkToHTML :: Link -> HTML
linkToHTML link = case rel link of
HomePage -> anchor (href link) "homepage"
Staff -> anchor (href link) "Staff page"
Pure -> anchor (href link) "Staff page (pure)"
Thesis -> anchor (href link) "PhD Thesis"
statusToHTML :: Status -> HTML
statusToHTML Academic = "Academic staff"
statusToHTML Research = "Research staff"
statusToHTML PhDStudent = "PhD student"
statusToHTML PhDFinished = "Alumnus (PhD)"
statusToHTML Alum = "Alumus"
personToHTML :: Person -> HTML
personToHTML person =
div "card"
(concat [ maybe "" (\fname -> img ("people-pics/" ++ fname)) (picture person)
, h5 (maybe "" (++" ") (title person) ++ name person)
, p (statusToHTML (status person))
, p (description person)
-- pronouns
, maybe "" emailToHTML (email person)
, maybe "" (ulist . map linkToHTML) (links person)
-- PhD topics
])
------------------------------------------------------------------------------
main :: IO ()
main = do
f <- BS.readFile "people.yaml"
case decodeEither' f of
Left err ->
error (show err)
Right people ->
putStrLn (unlines (map personToHTML people))