@@ -25,6 +25,8 @@ import Text.Hakyll.Renderable
2525import Text.Hakyll.File
2626import Text.Hakyll.CompressCSS
2727
28+import Control.Parallel.Strategies (rnf, ($|))
29+
2830-- | Execute an IO action only when the cache is invalid.
2931depends :: FilePath -- ^ File to be rendered or created.
3032 -> [FilePath] -- ^ Files the render depends on.
@@ -75,12 +77,13 @@ renderWith :: Renderable a
7577renderWith manipulation templatePath renderable = do
7678 handle <- openFile templatePath ReadMode
7779 templateString <- hGetContents handle
78− seq templateString $ hClose handle
7980 context <- liftM manipulation $ toContext renderable
8081 -- Ignore $root when substituting here. We will only replace that in the
8182 -- final render (just before writing).
8283 let contextIgnoringRoot = M.insert "root" "$root" context
8384 body = regularSubstitute templateString contextIgnoringRoot
85+ -- Force the body to be rendered before closing the handle.
86+ seq (($|) id rnf body) $ hClose handle
8487 return $ fromContext (M.insert "body" body context)
8588
8689-- | Render each renderable with the given template, then concatenate the