@@ -1,7 +1,10 @@
1module Text.Hakyll.Render
1module Text.Hakyll.Render
2− ( renderPage,
3+ renderPage,
3 renderAndWrite,
4 renderAndWrite,
4 renderAndConcat,
6 renderAndConcat,
6 staticDirectory
9 staticDirectory
@@ -17,6 +20,12 @@ import System.IO
17import Text.Hakyll.Page
20import Text.Hakyll.Page
18import Text.Hakyll.Util
21import Text.Hakyll.Util
23+depends :: FilePath -> [FilePath] -> IO () -> IO ()
24+depends file dependencies action = do
25+ valid <- isCacheValid (toDestination file) dependencies
26+ if valid then return ()
20createContext :: Page -> Context
29createContext :: Page -> Context
21createContext = M.fromList . map packPair . M.toList
30createContext = M.fromList . map packPair . M.toList
22 where packPair (a, b) = (B.pack a, b)
31 where packPair (a, b) = (B.pack a, b)
@@ -30,11 +39,14 @@ renderPage templatePath page = do
30 return $ M.insert "body" body page
39 return $ M.insert "body" body page
32renderAndWrite :: FilePath -> Page -> IO ()
41renderAndWrite :: FilePath -> Page -> IO ()
33−renderAndWrite templatePath page = do
42+renderAndWrite templatePath page =
34− rendered <- renderPage templatePath page
43+ renderPage templatePath page >>= writePage
45+writePage :: Page -> IO ()
35− let destination = toDestination $ getURL rendered
47+ let destination = toDestination $ getURL page
36 makeDirectories destination
48 makeDirectories destination
37− B.writeFile destination (getBody rendered)
49+ B.writeFile destination (getBody page)
39renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
51renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
40renderAndConcat templatePath paths = foldM concatRender' B.empty paths
52renderAndConcat templatePath paths = foldM concatRender' B.empty paths
@@ -45,6 +57,12 @@ renderAndConcat templatePath paths = foldM concatRender' B.empty paths
45 let body = getBody rendered
57 let body = getBody rendered
46 return $ B.append chunk $ body
58 return $ B.append chunk $ body
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
48static :: FilePath -> IO ()
66static :: FilePath -> IO ()
49static source = do
67static source = do
50 makeDirectories destination
68 makeDirectories destination