on master help sign in
Working with file handles so files get closed in time.
commit8cc0cb94fc913b882d71a41d8c65c19451a80b5f authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 4 Dec 2009, 00:15 (17 years ago) parent453932a
2 files changed+11−3
src/Text/Hakyll/Page.hs+7−2 src/Text/Hakyll/Render.hs+4−1
src/Text/Hakyll/Page.hs+7−2
@@ -11,8 +11,11 @@ module Text.Hakyll.Page
1111
1212import qualified Data.Map as M
1313import qualified Data.List as L
14−import System.FilePath
1514import Data.Maybe
15+
16+import System.FilePath
17+import System.IO
18+
1619import Text.Pandoc
1720
1821-- | A Page is basically key-value mapping. Certain keys have special
@@ -57,7 +60,9 @@ markdownToHTML = writeHtmlString writerOptions .
5760-- pages are not templates, so they should not contain $identifiers.
5861readPage :: FilePath -> IO Page
5962readPage path = do
60− content <- readFile path
63+ handle <- openFile path ReadMode
64+ content <- hGetContents handle
65+ seq content $ hClose handle
6166 let context = extractContext content
6267 body = (if takeExtension path == ".markdown" then markdownToHTML else id)
6368 (getBody context)
src/Text/Hakyll/Render.hs+4−1
@@ -12,6 +12,7 @@ import Control.Monad
1212
1313import System.FilePath
1414import System.Directory
15+import System.IO
1516
1617import Text.Hakyll.Page
1718import Text.Hakyll.Util
@@ -25,7 +26,9 @@ createContext = M.fromList . map packPair . M.toList
2526
2627renderPage :: FilePath -> Page -> IO Page
2728renderPage templatePath page = do
28− templateString <- B.readFile templatePath
29+ handle <- openFile templatePath ReadMode
30+ templateString <- liftM B.pack $ hGetContents handle
31+ seq templateString $ hClose handle
2932 let body = substitute templateString (createContext page)
3033 return $ addContext "body" (B.unpack body) page
3134