Some more strictness.
This commit is contained in:
parent
53d9ba2193
commit
0152a15b1e
2 changed files with 10 additions and 8 deletions
|
@ -92,9 +92,7 @@ cachePage page@(Page mapping) = do
|
|||
hPutStr handle $ getBody page
|
||||
hClose handle
|
||||
where
|
||||
writePair h (k, v) = do hPutStr h k
|
||||
hPutStr h ": "
|
||||
hPutStr h v
|
||||
writePair h (k, v) = do hPutStr h $ k ++ ": " ++ v
|
||||
hPutStrLn h ""
|
||||
|
||||
-- | Read a page from a file. Metadata is supported, and if the filename
|
||||
|
@ -109,12 +107,13 @@ readPage pagePath = do
|
|||
-- Read file.
|
||||
handle <- openFile path ReadMode
|
||||
line <- hGetLine handle
|
||||
(context, body) <-
|
||||
(metaData, body) <-
|
||||
if isDelimiter line
|
||||
then do md <- readMetaData handle
|
||||
c <- hGetContents handle
|
||||
return (md, c)
|
||||
else hGetContents handle >>= \b -> return ([], line ++ b)
|
||||
b <- hGetContents handle
|
||||
return (md, b)
|
||||
else do b <- hGetContents handle
|
||||
return ([], line ++ b)
|
||||
|
||||
-- Render file
|
||||
let rendered = (renderFunction $ takeExtension path) body
|
||||
|
|
|
@ -25,6 +25,8 @@ import Text.Hakyll.Renderable
|
|||
import Text.Hakyll.File
|
||||
import Text.Hakyll.CompressCSS
|
||||
|
||||
import Control.Parallel.Strategies (rnf, ($|))
|
||||
|
||||
-- | Execute an IO action only when the cache is invalid.
|
||||
depends :: FilePath -- ^ File to be rendered or created.
|
||||
-> [FilePath] -- ^ Files the render depends on.
|
||||
|
@ -75,12 +77,13 @@ renderWith :: Renderable a
|
|||
renderWith manipulation templatePath renderable = do
|
||||
handle <- openFile templatePath ReadMode
|
||||
templateString <- hGetContents handle
|
||||
seq templateString $ hClose handle
|
||||
context <- liftM manipulation $ toContext renderable
|
||||
-- Ignore $root when substituting here. We will only replace that in the
|
||||
-- final render (just before writing).
|
||||
let contextIgnoringRoot = M.insert "root" "$root" context
|
||||
body = regularSubstitute templateString contextIgnoringRoot
|
||||
-- Force the body to be rendered before closing the handle.
|
||||
seq (($|) id rnf body) $ hClose handle
|
||||
return $ fromContext (M.insert "body" body context)
|
||||
|
||||
-- | Render each renderable with the given template, then concatenate the
|
||||
|
|
Loading…
Reference in a new issue