@@ -52,7 +52,10 @@ renderWith manipulation templatePath renderable = do
52 templateString <- liftM B.pack $ hGetContents handle
52 templateString <- liftM B.pack $ hGetContents handle
53 seq templateString $ hClose handle
53 seq templateString $ hClose handle
54 context <- liftM manipulation $ toContext renderable
54 context <- liftM manipulation $ toContext renderable
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
55− let body = substitute templateString context
58+ body = substitute templateString contextIgnoringRoot
56 return $ fromContext (M.insert (B.pack "body") body context)
59 return $ fromContext (M.insert (B.pack "body") body context)
58-- | Render each renderable with the given template, then concatenate the
61-- | Render each renderable with the given template, then concatenate the
@@ -92,6 +95,17 @@ renderChainWith manipulation templates renderable =
92 result <- foldM (flip render) (fromContext initialPage) templates
95 result <- foldM (flip render) (fromContext initialPage) templates
93 writePage result
96 writePage result
98+-- | Write a page to the site destination.
99+writePage :: Page -> IO ()
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))
95-- | Mark a certain file as static, so it will just be copied when the site is
109-- | Mark a certain file as static, so it will just be copied when the site is
96-- generated.
110-- generated.
97static :: FilePath -> IO ()
111static :: FilePath -> IO ()