hakyll/src/Hakyll/Web/Page.hs

41 lines
1 KiB
Haskell
Raw Normal View History

2010-12-26 18:03:03 +00:00
-- | A page is an important concept in Hakyll: it has a body (usually of the
-- type 'String') and number of metadata fields. This type is used to represent
-- pages on your website.
--
2010-12-28 10:12:45 +00:00
{-# LANGUAGE DeriveDataTypeable #-}
2010-12-26 18:03:03 +00:00
module Hakyll.Web.Page
( Page (..)
, toMap
) where
2010-12-27 17:46:23 +00:00
import Control.Applicative ((<$>), (<*>))
2010-12-26 18:03:03 +00:00
import Data.Map (Map)
import qualified Data.Map as M
2010-12-27 17:46:23 +00:00
import Data.Binary (Binary, get, put)
2010-12-28 10:12:45 +00:00
import Data.Typeable (Typeable)
2010-12-26 18:03:03 +00:00
import Hakyll.Core.Writable
-- | Type used to represent pages
--
data Page a = Page
{ pageMetadata :: Map String String
, pageBody :: a
2010-12-28 10:12:45 +00:00
} deriving (Show, Typeable)
2010-12-26 18:03:03 +00:00
instance Functor Page where
fmap f (Page m b) = Page m (f b)
2010-12-27 17:46:23 +00:00
instance Binary a => Binary (Page a) where
put (Page m b) = put m >> put b
get = Page <$> get <*> get
2010-12-26 18:03:03 +00:00
instance Writable a => Writable (Page a) where
write p (Page _ b) = write p b
-- | Convert a page to a map. The body will be placed in the @body@ key.
--
toMap :: Page String -> Map String String
toMap (Page m b) = M.insert "body" b m