summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Render.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-10 13:26:57 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-10 13:26:57 +0100
commit6a2e6998b125024e9260d26819c262e0e7d22c8d (patch)
treeb00286fa709701e6e072e84d4f7225d8d6fbd801 /src/Text/Hakyll/Render.hs
parentbc71d54ab732d71e2f1a3c5e3dce9f3231334605 (diff)
downloadhakyll-6a2e6998b125024e9260d26819c262e0e7d22c8d.tar.gz
Worked on substitution.
Diffstat (limited to 'src/Text/Hakyll/Render.hs')
-rw-r--r--src/Text/Hakyll/Render.hs16
1 files changed, 15 insertions, 1 deletions
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 ()