Add index type
This commit is contained in:
parent
9690477272
commit
e258eaf123
11
src/Types.hs
11
src/Types.hs
|
@ -15,6 +15,7 @@ module Types
|
||||||
( Audiobook
|
( Audiobook
|
||||||
, Episode(Episode)
|
, Episode(Episode)
|
||||||
, Podcast(Podcast)
|
, Podcast(Podcast)
|
||||||
|
, Index(Index)
|
||||||
, makeAudiobook
|
, makeAudiobook
|
||||||
, makeAudiobookWithAuthor
|
, makeAudiobookWithAuthor
|
||||||
, toAudiobookWithAuthor
|
, toAudiobookWithAuthor
|
||||||
|
@ -79,6 +80,10 @@ data Podcast = Podcast { audiobook :: Audiobook
|
||||||
}
|
}
|
||||||
deriving (Show)
|
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 -> [Pair]
|
||||||
toPairList audiobook =
|
toPairList audiobook =
|
||||||
[ "audiobook-title" ~> audiobookTitle audiobook
|
[ "audiobook-title" ~> audiobookTitle audiobook
|
||||||
|
@ -104,9 +109,13 @@ instance ToMustache Audiobook where
|
||||||
instance ToMustache Podcast where
|
instance ToMustache Podcast where
|
||||||
toMustache podcast = object $ [
|
toMustache podcast = object $ [
|
||||||
"base-url" ~> baseUrl podcast,
|
"base-url" ~> baseUrl podcast,
|
||||||
"pub-day" ~> show (pubDay podcast)
|
"pub-day" ~> show (pubDay podcast),
|
||||||
|
"audiobook-file" ~> generatePodcastFileName podcast
|
||||||
] ++ (toPairList (audiobook podcast))
|
] ++ (toPairList (audiobook podcast))
|
||||||
|
|
||||||
|
instance ToMustache Index where
|
||||||
|
toMustache (Index podcasts) = object ["entries" ~> podcasts]
|
||||||
|
|
||||||
generatePodcast :: Day -> String -> Audiobook -> Podcast
|
generatePodcast :: Day -> String -> Audiobook -> Podcast
|
||||||
generatePodcast day url audiobook = Podcast audiobook url day
|
generatePodcast day url audiobook = Podcast audiobook url day
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue