From e258eaf123dec9157b8a61317b8ea503e50a167f Mon Sep 17 00:00:00 2001 From: norangebit Date: Tue, 26 Jan 2021 14:57:38 +0100 Subject: [PATCH] Add index type --- src/Types.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Types.hs b/src/Types.hs index 559a5ae..bb3731c 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -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