on master help sign in
Added CustomPage.
commitd988921714f3335b9755e30ea893e3e2b47d72b6 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 11 Dec 2009, 20:41 (17 years ago) parentd83791c
3 files changed+35−6
hakyll.cabal+1 src/Text/Hakyll/CustomPage.hs+29 src/Text/Hakyll/Render.hs+5−6
hakyll.cabal+1
@@ -23,5 +23,6 @@ library
2323 exposed-modules: Text.Hakyll.Render
2424 Text.Hakyll.Renderable
2525 Text.Hakyll.Page
26+ Text.Hakyll.CustomPage
2627 Text.Hakyll.RenderableFilePath
2728 Text.Hakyll.Util
src/Text/Hakyll/CustomPage.hsnew file+29
@@ -0,0 +1,29 @@
1+module Text.Hakyll.CustomPage
2+ ( CustomPage,
3+ createCustomPage
4+ ) where
5+
6+import System.FilePath
7+import qualified Data.ByteString.Lazy.Char8 as B
8+import qualified Data.Map as M
9+import Control.Monad
10+import Text.Hakyll.Renderable
11+
12+data CustomPage = CustomPage { url :: String,
13+ dependencies :: [FilePath],
14+ mapping :: [(String, Either String (IO B.ByteString))]
15+ }
16+
17+createCustomPage :: String
18+ -> [FilePath]
19+ -> [(String, Either String (IO B.ByteString))]
20+ -> CustomPage
21+createCustomPage = CustomPage
22+
23+instance Renderable CustomPage where
24+ getDependencies = dependencies
25+ getURL = url
26+ toContext page = do
27+ values <- mapM (either (return . B.pack) (>>= return) . snd) (mapping page)
28+ let keys = map (B.pack . fst) (mapping page)
29+ return $ M.fromList $ (B.pack "url", B.pack $ url page) : zip keys values
src/Text/Hakyll/Render.hs+5−6
@@ -40,12 +40,11 @@ writePage page = do
4040 makeDirectories destination
4141 B.writeFile destination (getBody page)
4242
43−renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
44−renderAndConcat templatePath paths = foldM concatRender' B.empty paths
45− where concatRender' :: B.ByteString -> FilePath -> IO B.ByteString
46− concatRender' chunk path = do
47− page <- readPage path
48− rendered <- render templatePath page
43+renderAndConcat :: Renderable a => FilePath -> [a] -> IO B.ByteString
44+renderAndConcat templatePath renderables = foldM concatRender' B.empty renderables
45+ where concatRender' :: Renderable a => B.ByteString -> a -> IO B.ByteString
46+ concatRender' chunk renderable = do
47+ rendered <- render templatePath renderable
4948 let body = getBody rendered
5049 return $ B.append chunk $ body
5150