Add index type

This commit is contained in:
Raffaele Mignone 2021-01-26 14:57:38 +01:00
parent 9690477272
commit e258eaf123
Signed by: norangebit
GPG Key ID: F5255658CB220573
1 changed files with 10 additions and 1 deletions

View File

@ -15,6 +15,7 @@ module Types
( Audiobook
, Episode(Episode)
, Podcast(Podcast)
, Index(Index)
, makeAudiobook
, makeAudiobookWithAuthor
, toAudiobookWithAuthor
@ -79,6 +80,10 @@ data Podcast = Podcast { audiobook :: Audiobook
}
deriving (Show)
-- | The 'Index' data type represents a list of podcast.
-- `Index' is an instance of 'ToMustache' typeclass.
newtype Index = Index [Podcast]
toPairList :: Audiobook -> [Pair]
toPairList audiobook =
[ "audiobook-title" ~> audiobookTitle audiobook
@ -104,9 +109,13 @@ instance ToMustache Audiobook where
instance ToMustache Podcast where
toMustache podcast = object $ [
"base-url" ~> baseUrl podcast,
"pub-day" ~> show (pubDay podcast)
"pub-day" ~> show (pubDay podcast),
"audiobook-file" ~> generatePodcastFileName podcast
] ++ (toPairList (audiobook podcast))
instance ToMustache Index where
toMustache (Index podcasts) = object ["entries" ~> podcasts]
generatePodcast :: Day -> String -> Audiobook -> Podcast
generatePodcast day url audiobook = Podcast audiobook url day