used DeriveAny to derive Binary & FromJSON instances
This commit is contained in:
parent
dbae6b3623
commit
9598b36d69
|
@ -10,7 +10,6 @@ executable site
|
|||
hs-source-dirs: src
|
||||
other-modules: Templates
|
||||
, Types
|
||||
, Page
|
||||
, Posts
|
||||
, Projects
|
||||
, Common
|
||||
|
|
|
@ -9,16 +9,22 @@ module Common
|
|||
, module Control.Monad
|
||||
, module Data.Maybe
|
||||
, module Lucid
|
||||
, module Data.Binary
|
||||
, module GHC.Generics
|
||||
, module Data.Aeson.Types
|
||||
) where
|
||||
|
||||
import Achille
|
||||
import Achille.Recipe.Pandoc
|
||||
|
||||
import Data.Functor ((<&>))
|
||||
import Control.Monad (forM_, when)
|
||||
import Data.Sort (sort)
|
||||
import Data.String (fromString)
|
||||
import Data.Text (Text)
|
||||
import Data.Maybe (fromMaybe, mapMaybe)
|
||||
import Data.Aeson.Types (FromJSON)
|
||||
import GHC.Generics (Generic)
|
||||
import Data.Binary (Binary)
|
||||
import Data.Functor ((<&>))
|
||||
import Control.Monad (forM_, when)
|
||||
import Data.Sort (sort)
|
||||
import Data.String (fromString)
|
||||
import Data.Text (Text)
|
||||
import Data.Maybe (fromMaybe, mapMaybe)
|
||||
import System.FilePath
|
||||
import Lucid (Html)
|
||||
import Lucid (Html)
|
||||
|
|
|
@ -5,10 +5,11 @@ import Lucid
|
|||
|
||||
import Common
|
||||
import Templates
|
||||
import Config (config, ropts, wopts, SiteConfig(title))
|
||||
|
||||
import qualified Posts
|
||||
import qualified Projects
|
||||
import qualified Visual
|
||||
import Config (config, ropts, wopts, SiteConfig(title))
|
||||
|
||||
|
||||
main :: IO ()
|
||||
|
|
13
src/Page.hs
13
src/Page.hs
|
@ -1,13 +0,0 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
|
||||
module Page where
|
||||
|
||||
import GHC.Generics
|
||||
import Data.Aeson.Types (FromJSON)
|
||||
|
||||
data Page = Page
|
||||
{ title :: String
|
||||
, draft :: Maybe Bool
|
||||
} deriving (Generic, Eq, Show)
|
||||
|
||||
instance FromJSON Page
|
11
src/Posts.hs
11
src/Posts.hs
|
@ -1,5 +1,3 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
|
||||
module Posts (build) where
|
||||
|
||||
import Data.Aeson.Types (FromJSON)
|
||||
|
@ -24,7 +22,7 @@ data PostMeta = PostMeta
|
|||
{ title :: Text
|
||||
, draft :: Maybe Bool
|
||||
, description :: Maybe Text
|
||||
} deriving (Generic, Eq, Show)
|
||||
} deriving (Generic, Eq, Show, FromJSON)
|
||||
|
||||
data Post = Post
|
||||
{ postTitle :: Text
|
||||
|
@ -33,14 +31,9 @@ data Post = Post
|
|||
, postDescription :: Maybe Text
|
||||
, postContent :: Text
|
||||
, postPath :: FilePath
|
||||
} deriving (Generic, Eq, Show)
|
||||
} deriving (Generic, Eq, Show, Binary)
|
||||
|
||||
instance FromJSON PostMeta
|
||||
instance IsTimestamped Post where timestamp = postDate
|
||||
instance Binary Post where
|
||||
put (Post t d dr desc content path) =
|
||||
put t >> put d >> put dr >> put desc >> put content >> put path
|
||||
get = Post <$> get <*> get <*> get <*> get <*> get <*> get
|
||||
|
||||
|
||||
buildPost :: Recipe IO FilePath Post
|
||||
|
|
|
@ -4,7 +4,6 @@ import Data.Char (digitToInt)
|
|||
|
||||
import Common
|
||||
import Types
|
||||
import Page
|
||||
import Config
|
||||
import Templates
|
||||
import Lucid
|
||||
|
|
25
src/Types.hs
25
src/Types.hs
|
@ -1,16 +1,11 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
|
||||
module Types where
|
||||
|
||||
import GHC.Generics
|
||||
import Data.Aeson.Types (FromJSON)
|
||||
import Data.Binary (Binary, put, get)
|
||||
import Data.Time.LocalTime (ZonedTime)
|
||||
import Data.Binary.Instances.Time ()
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Map.Strict as Map
|
||||
|
||||
import Common
|
||||
|
||||
-- | Full project description
|
||||
data Project = Project
|
||||
|
@ -19,13 +14,13 @@ data Project = Project
|
|||
, year :: String
|
||||
, labels :: Map.Map String String
|
||||
, gallery :: Maybe Bool
|
||||
} deriving (Generic, Eq, Show)
|
||||
} deriving (Generic, Eq, Show, FromJSON, Binary)
|
||||
|
||||
|
||||
data TitledPage = TitledPage
|
||||
{ title :: String
|
||||
, description :: Maybe String
|
||||
} deriving (Generic, Eq, Show)
|
||||
} deriving (Generic, Eq, Show, FromJSON, Binary)
|
||||
|
||||
|
||||
-- | Book description for the readings page
|
||||
|
@ -34,16 +29,4 @@ data Book = Book
|
|||
, author :: Text
|
||||
, rating :: Maybe Int
|
||||
, completed :: Maybe ZonedTime
|
||||
} deriving (Generic, Show)
|
||||
|
||||
instance FromJSON Project
|
||||
instance FromJSON TitledPage
|
||||
instance FromJSON Book
|
||||
|
||||
instance Binary Project where
|
||||
put (Project t s y l g) = put t >> put s >> put y >> put l >> put g
|
||||
get = Project <$> get <*> get <*> get <*> get <*> get
|
||||
|
||||
instance Binary Book where
|
||||
put (Book t a r c) = put t >> put a >> put r >> put c
|
||||
get = Book <$> get <*> get <*> get <*> get
|
||||
} deriving (Generic, Show, FromJSON)
|
||||
|
|
Loading…
Reference in New Issue