@@ -52,7 +52,10 @@ renderWith manipulation templatePath renderable = do
5252 templateString <- liftM B.pack $ hGetContents handle
5353 seq templateString $ hClose handle
5454 context <- liftM manipulation $ toContext renderable
55− let body = substitute templateString context
55+ -- Ignore $root when substituting here. We will only replace that in the
56+ -- final render (just before writing).
57+ let contextIgnoringRoot = M.insert (B.pack "root") (B.pack "$root") context
58+ body = substitute templateString contextIgnoringRoot
5659 return $ fromContext (M.insert (B.pack "body") body context)
5760
5861-- | Render each renderable with the given template, then concatenate the
@@ -92,6 +95,17 @@ renderChainWith manipulation templates renderable =
9295 result <- foldM (flip render) (fromContext initialPage) templates
9396 writePage result
9497
98+-- | Write a page to the site destination.
99+writePage :: Page -> IO ()
100+writePage page = do
101+ let destination = toDestination url
102+ makeDirectories destination
103+ B.writeFile destination body
104+ where url = getURL page
105+ -- Substitute $root here, just before writing.
106+ body = substitute (getBody page)
107+ (M.singleton (B.pack "root") (B.pack $ toRoot url))
108+
95109-- | Mark a certain file as static, so it will just be copied when the site is
96110-- generated.
97111static :: FilePath -> IO ()