From 0c677070edf9978cb85a0b521f7e6e0ef6d6b491 Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Mon, 10 Feb 2025 12:48:38 -0600 Subject: A lot of work on aliases and the like --- src/Data/Journal.hs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Data/Journal.hs (limited to 'src/Data/Journal.hs') diff --git a/src/Data/Journal.hs b/src/Data/Journal.hs new file mode 100644 index 0000000..ea15644 --- /dev/null +++ b/src/Data/Journal.hs @@ -0,0 +1,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 -- cgit v1.2.3