blob: ea156440a53cbd48ac9d3730f115a981f5460d49 (
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
|
module Data.Journal
( Journal (..)
, Journal_
, journalHtml
) where
import Prolog
import Network.URI
import Data.Aeson
import Data.Alias
import Data.Set qualified as S
import Text.Blaze
import Text.Blaze.Html
import Data.Linked
data Journal a = Journal
{ title :: !a
, shortTitle :: !(Maybe a)
, link :: !(Maybe URI)
} deriving (Eq, Foldable, Functor, Generic, Ord, Show, Traversable)
instance Binary a => Binary (Journal a)
type Journal_ = Journal StrictText
journalHtml :: (ToMarkup a) => Journal a -> Html
journalHtml (Journal t st l) = linkedHtml $ Linked (maybe t id st) l (t <$ st)
instance Ord a => ToAliases (Journal a) a where
toAliases (Journal t st _) = S.fromList $ t : toList st
instance FromAlias a (Journal a) where
fromAlias t = pure $ Journal t Nothing Nothing
instance FromJSON a => FromJSON (Journal a) where
parseJSON = withObject "Journal" $ \v -> Journal
<$> v .: "title"
<*> v .:? "short" .!= Nothing
<*> v .:? "link" .!= Nothing
|