From 8cc0cb94fc913b882d71a41d8c65c19451a80b5f Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 4 Dec 2009 00:15:28 +0100 Subject: Working with file handles so files get closed in time. --- src/Text/Hakyll/Page.hs | 9 +++++++-- src/Text/Hakyll/Render.hs | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs index 5b3586d..5b4d962 100644 --- a/src/Text/Hakyll/Page.hs +++ b/src/Text/Hakyll/Page.hs @@ -11,8 +11,11 @@ module Text.Hakyll.Page import qualified Data.Map as M import qualified Data.List as L -import System.FilePath import Data.Maybe + +import System.FilePath +import System.IO + import Text.Pandoc -- | A Page is basically key-value mapping. Certain keys have special @@ -57,7 +60,9 @@ markdownToHTML = writeHtmlString writerOptions . -- pages are not templates, so they should not contain $identifiers. readPage :: FilePath -> IO Page readPage path = do - content <- readFile path + handle <- openFile path ReadMode + content <- hGetContents handle + seq content $ hClose handle let context = extractContext content body = (if takeExtension path == ".markdown" then markdownToHTML else id) (getBody context) diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs index 2ff1b93..54df1b4 100644 --- a/src/Text/Hakyll/Render.hs +++ b/src/Text/Hakyll/Render.hs @@ -12,6 +12,7 @@ import Control.Monad import System.FilePath import System.Directory +import System.IO import Text.Hakyll.Page import Text.Hakyll.Util @@ -25,7 +26,9 @@ createContext = M.fromList . map packPair . M.toList renderPage :: FilePath -> Page -> IO Page renderPage templatePath page = do - templateString <- B.readFile templatePath + handle <- openFile templatePath ReadMode + templateString <- liftM B.pack $ hGetContents handle + seq templateString $ hClose handle let body = substitute templateString (createContext page) return $ addContext "body" (B.unpack body) page -- cgit v1.2.3