summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Page.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-15 09:47:07 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-15 09:47:07 +0100
commit62330ceae51ea28f75768196ad5e3f93eb88b8a3 (patch)
treea3a45aa9e0d63c65eb4fc4e7a4277fde645b8f48 /src/Text/Hakyll/Page.hs
parenta180016488d0fed843f525db824dc0c24cde90ca (diff)
downloadhakyll-62330ceae51ea28f75768196ad5e3f93eb88b8a3.tar.gz
Moved some more functions from the IO monad to the Hakyll monad stack.
Diffstat (limited to 'src/Text/Hakyll/Page.hs')
-rw-r--r--src/Text/Hakyll/Page.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index 6c73ff3..652a1c6 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -84,26 +84,30 @@ isDelimiter = L.isPrefixOf "---"
-- | Used for caching of files.
cachePage :: Page -> Hakyll ()
-cachePage page@(Page mapping) = liftIO $ do
- let destination = toCache $ getURL page
+cachePage page@(Page mapping) = do
makeDirectories destination
- handle <- openFile destination WriteMode
- hPutStrLn handle "---"
- mapM_ (writePair handle) $ M.toList $ M.delete "body" mapping
- hPutStrLn handle "---"
- hPutStr handle $ getBody page
- hClose handle
+ liftIO writePageToCache
where
+ writePageToCache = do
+ handle <- openFile destination WriteMode
+ hPutStrLn handle "---"
+ mapM_ (writePair handle) $ M.toList $ M.delete "body" mapping
+ hPutStrLn handle "---"
+ hPutStr handle $ getBody page
+ hClose handle
+
writePair h (k, v) = do hPutStr h $ k ++ ": " ++ v
hPutStrLn h ""
+ destination = toCache $ getURL page
+
-- | Read a page from a file. Metadata is supported, and if the filename
-- has a .markdown extension, it will be rendered using pandoc. Note that
-- pages are not templates, so they should not contain $identifiers.
readPage :: FilePath -> Hakyll Page
readPage pagePath = do
-- Check cache.
- getFromCache <- liftIO $ isCacheValid cacheFile [pagePath]
+ getFromCache <- isCacheValid cacheFile [pagePath]
let path = if getFromCache then cacheFile else pagePath
-- Read file.