summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Render.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-07 20:34:45 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-07 20:34:45 +0100
commit453e81f746c3a0e254457881cc0ac8609874cf32 (patch)
tree642446fc76fbbfcd7525a0cc6ecf752d54b5309b /src/Text/Hakyll/Render.hs
parent35e6572f6c30ffa9db61bb9ab71478cfb8d6aed1 (diff)
downloadhakyll-453e81f746c3a0e254457881cc0ac8609874cf32.tar.gz
Added basic dependency checking.
Diffstat (limited to 'src/Text/Hakyll/Render.hs')
-rw-r--r--src/Text/Hakyll/Render.hs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index 79f8764..a554fd5 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -1,7 +1,10 @@
module Text.Hakyll.Render
- ( renderPage,
+ ( depends,
+ renderPage,
renderAndWrite,
+ writePage,
renderAndConcat,
+ renderChain,
static,
staticDirectory
) where
@@ -17,6 +20,12 @@ import System.IO
import Text.Hakyll.Page
import Text.Hakyll.Util
+depends :: FilePath -> [FilePath] -> IO () -> IO ()
+depends file dependencies action = do
+ valid <- isCacheValid (toDestination file) dependencies
+ if valid then return ()
+ else action
+
createContext :: Page -> Context
createContext = M.fromList . map packPair . M.toList
where packPair (a, b) = (B.pack a, b)
@@ -30,11 +39,14 @@ renderPage templatePath page = do
return $ M.insert "body" body page
renderAndWrite :: FilePath -> Page -> IO ()
-renderAndWrite templatePath page = do
- rendered <- renderPage templatePath page
- let destination = toDestination $ getURL rendered
+renderAndWrite templatePath page =
+ renderPage templatePath page >>= writePage
+
+writePage :: Page -> IO ()
+writePage page = do
+ let destination = toDestination $ getURL page
makeDirectories destination
- B.writeFile destination (getBody rendered)
+ B.writeFile destination (getBody page)
renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
renderAndConcat templatePath paths = foldM concatRender' B.empty paths
@@ -45,6 +57,12 @@ renderAndConcat templatePath paths = foldM concatRender' B.empty paths
let body = getBody rendered
return $ B.append chunk $ body
+renderChain :: FilePath -> [FilePath] -> IO ()
+renderChain pagePath templates = depends (toURL pagePath) (pagePath : templates) $
+ do page <- readPage pagePath
+ result <- foldM (flip renderPage) page templates
+ writePage result
+
static :: FilePath -> IO ()
static source = do
makeDirectories destination