@@ -1,7 +1,10 @@
11module Text.Hakyll.Render
2− ( renderPage,
2+ ( depends,
3+ renderPage,
34 renderAndWrite,
5+ writePage,
46 renderAndConcat,
7+ renderChain,
58 static,
69 staticDirectory
710 ) where
@@ -17,6 +20,12 @@ import System.IO
1720import Text.Hakyll.Page
1821import Text.Hakyll.Util
1922
23+depends :: FilePath -> [FilePath] -> IO () -> IO ()
24+depends file dependencies action = do
25+ valid <- isCacheValid (toDestination file) dependencies
26+ if valid then return ()
27+ else action
28+
2029createContext :: Page -> Context
2130createContext = M.fromList . map packPair . M.toList
2231 where packPair (a, b) = (B.pack a, b)
@@ -30,11 +39,14 @@ renderPage templatePath page = do
3039 return $ M.insert "body" body page
3140
3241renderAndWrite :: FilePath -> Page -> IO ()
33−renderAndWrite templatePath page = do
34− rendered <- renderPage templatePath page
35− let destination = toDestination $ getURL rendered
42+renderAndWrite templatePath page =
43+ renderPage templatePath page >>= writePage
44+
45+writePage :: Page -> IO ()
46+writePage page = do
47+ let destination = toDestination $ getURL page
3648 makeDirectories destination
37− B.writeFile destination (getBody rendered)
49+ B.writeFile destination (getBody page)
3850
3951renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
4052renderAndConcat templatePath paths = foldM concatRender' B.empty paths
@@ -45,6 +57,12 @@ renderAndConcat templatePath paths = foldM concatRender' B.empty paths
4557 let body = getBody rendered
4658 return $ B.append chunk $ body
4759
60+renderChain :: FilePath -> [FilePath] -> IO ()
61+renderChain pagePath templates = depends (toURL pagePath) (pagePath : templates) $
62+ do page <- readPage pagePath
63+ result <- foldM (flip renderPage) page templates
64+ writePage result
65+
4866static :: FilePath -> IO ()
4967static source = do
5068 makeDirectories destination