summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Render.hs
diff options
context:
space:
mode:
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