on master help sign in
Some more strictness.
commit0152a15b1e625b447ccb9d8a7956d026b401c31a authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 12 Jan 2010, 08:40 (17 years ago) parent53d9ba2
2 files changed+10−8
src/Text/Hakyll/Page.hs+6−7 src/Text/Hakyll/Render.hs+4−1
src/Text/Hakyll/Page.hs+6−7
@@ -92,9 +92,7 @@ cachePage page@(Page mapping) = do
9292 hPutStr handle $ getBody page
9393 hClose handle
9494 where
95− writePair h (k, v) = do hPutStr h k
96− hPutStr h ": "
97− hPutStr h v
95+ writePair h (k, v) = do hPutStr h $ k ++ ": " ++ v
9896 hPutStrLn h ""
9997
10098-- | Read a page from a file. Metadata is supported, and if the filename
@@ -109,12 +107,13 @@ readPage pagePath = do
109107 -- Read file.
110108 handle <- openFile path ReadMode
111109 line <- hGetLine handle
112− (context, body) <-
110+ (metaData, body) <-
113111 if isDelimiter line
114112 then do md <- readMetaData handle
115− c <- hGetContents handle
116− return (md, c)
117− else hGetContents handle >>= \b -> return ([], line ++ b)
113+ b <- hGetContents handle
114+ return (md, b)
115+ else do b <- hGetContents handle
116+ return ([], line ++ b)
118117
119118 -- Render file
120119 let rendered = (renderFunction $ takeExtension path) body
src/Text/Hakyll/Render.hs+4−1
@@ -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