From 6a2e6998b125024e9260d26819c262e0e7d22c8d Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 10 Jan 2010 13:26:57 +0100 Subject: Worked on substitution. --- src/Text/Hakyll/Render.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/Text/Hakyll/Render.hs') diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs index ac529e8..d3e4a34 100644 --- a/src/Text/Hakyll/Render.hs +++ b/src/Text/Hakyll/Render.hs @@ -52,7 +52,10 @@ renderWith manipulation templatePath renderable = do templateString <- liftM B.pack $ hGetContents handle seq templateString $ hClose handle context <- liftM manipulation $ toContext renderable - let body = substitute templateString context + -- Ignore $root when substituting here. We will only replace that in the + -- final render (just before writing). + let contextIgnoringRoot = M.insert (B.pack "root") (B.pack "$root") context + body = substitute templateString contextIgnoringRoot return $ fromContext (M.insert (B.pack "body") body context) -- | Render each renderable with the given template, then concatenate the @@ -92,6 +95,17 @@ renderChainWith manipulation templates renderable = result <- foldM (flip render) (fromContext initialPage) templates writePage result +-- | Write a page to the site destination. +writePage :: Page -> IO () +writePage page = do + let destination = toDestination url + makeDirectories destination + B.writeFile destination body + where url = getURL page + -- Substitute $root here, just before writing. + body = substitute (getBody page) + (M.singleton (B.pack "root") (B.pack $ toRoot url)) + -- | Mark a certain file as static, so it will just be copied when the site is -- generated. static :: FilePath -> IO () -- cgit v1.2.3