on 333c19d help sign in
hakyll/src/Text/Hakyll/Renderables.hs
44 lines 1.4 kB history raw
1module Text.Hakyll.Renderables
2 ( CustomPage,
3 createCustomPage,
4 PagePath,
5 createPagePath
6 ) where
8import System.FilePath
9import qualified Data.ByteString.Lazy.Char8 as B
10import qualified Data.Map as M
11import Control.Monad
12import Text.Hakyll.Util
13import Text.Hakyll.Page
14import Text.Hakyll.Renderable
16data CustomPage = CustomPage { url :: String,
17 dependencies :: [FilePath],
18 mapping :: [(String, Either String (IO B.ByteString))]
19 }
21createCustomPage :: String
22 -> [FilePath]
23 -> [(String, Either String (IO B.ByteString))]
24 -> CustomPage
25createCustomPage = CustomPage
27instance Renderable CustomPage where
28 getDependencies = dependencies
29 getURL = url
30 toContext page = do
31 values <- mapM (either (return . B.pack) (>>= return) . snd) (mapping page)
32 let keys = map (B.pack . fst) (mapping page)
33 return $ M.fromList $ (B.pack "url", B.pack $ url page) : zip keys values
35data PagePath = PagePath FilePath
37createPagePath :: FilePath -> PagePath
38createPagePath = PagePath
40-- We can render filepaths
41instance Renderable PagePath where
42 getDependencies (PagePath path) = return path
43 getURL (PagePath path) = toURL path
44 toContext (PagePath path) = readPage path >>= toContext