on master help sign in
Working with file handles so files get closed in time.
8cc0cb9Jasper Van der Jeugt
src/Text/Hakyll/Page.hs+7−2
@@ -11,8 +11,11 @@ module Text.Hakyll.Page
11
11
12import qualified Data.Map as M
12import qualified Data.Map as M
13import qualified Data.List as L
13import qualified Data.List as L
14−import System.FilePath
15import Data.Maybe
14import Data.Maybe
15+
16+import System.FilePath
17+import System.IO
18+
16import Text.Pandoc
19import Text.Pandoc
17
20
18-- | A Page is basically key-value mapping. Certain keys have special
21-- | A Page is basically key-value mapping. Certain keys have special
@@ -57,7 +60,9 @@ markdownToHTML = writeHtmlString writerOptions .
57-- pages are not templates, so they should not contain $identifiers.
60-- pages are not templates, so they should not contain $identifiers.
58readPage :: FilePath -> IO Page
61readPage :: FilePath -> IO Page
59readPage path = do
62readPage path = do
60− content <- readFile path
63+ handle <- openFile path ReadMode
64+ content <- hGetContents handle
65+ seq content $ hClose handle
61 let context = extractContext content
66 let context = extractContext content
62 body = (if takeExtension path == ".markdown" then markdownToHTML else id)
67 body = (if takeExtension path == ".markdown" then markdownToHTML else id)
63 (getBody context)
68 (getBody context)
src/Text/Hakyll/Render.hs+4−1
@@ -12,6 +12,7 @@ import Control.Monad
12
12
13import System.FilePath
13import System.FilePath
14import System.Directory
14import System.Directory
15+import System.IO
15
16
16import Text.Hakyll.Page
17import Text.Hakyll.Page
17import Text.Hakyll.Util
18import Text.Hakyll.Util
@@ -25,7 +26,9 @@ createContext = M.fromList . map packPair . M.toList
25
26
26renderPage :: FilePath -> Page -> IO Page
27renderPage :: FilePath -> Page -> IO Page
27renderPage templatePath page = do
28renderPage 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
29 let body = substitute templateString (createContext page)
32 let body = substitute templateString (createContext page)
30 return $ addContext "body" (B.unpack body) page
33 return $ addContext "body" (B.unpack body) page
31
34