diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-04 00:15:28 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-04 00:15:28 +0100 |
commit | 8cc0cb94fc913b882d71a41d8c65c19451a80b5f (patch) | |
tree | 83344154cebd4dc92049bf09b3c8e5474de87893 | |
parent | 453932a8b878cff86c41fc374b41d6d51dbe5a3f (diff) | |
download | hakyll-8cc0cb94fc913b882d71a41d8c65c19451a80b5f.tar.gz |
Working with file handles so files get closed in time.
-rw-r--r-- | src/Text/Hakyll/Page.hs | 9 | ||||
-rw-r--r-- | 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 |