@@ -18,6 +18,7 @@ import System.IO
1818
1919import Text.Pandoc
2020
21+import Text.Hakyll.Internal.Cache
2122import Text.Hakyll.Hakyll (Hakyll)
2223import Text.Hakyll.File
2324import Text.Hakyll.Util (trim)
@@ -28,6 +29,7 @@ import Text.Hakyll.Regex (substituteRegex, matchesRegex)
2829-- | A Page is basically key-value mapping. Certain keys have special
2930-- meanings, like for example url, body and title.
3031data Page = Page Context
32+ deriving (Show, Read)
3133
3234-- | Create a Page from a key-value mapping.
3335fromContext :: Context -> Page
@@ -110,8 +112,8 @@ readSection renderFunction isFirst ls
110112
111113-- | Read a page from a file. Metadata is supported, and if the filename
112114-- has a @.markdown@ extension, it will be rendered using pandoc.
113−readPage :: FilePath -> Hakyll Page
114−readPage path = do
115+readPageFromFile :: FilePath -> Hakyll Page
116+readPageFromFile path = do
115117 let renderFunction = getRenderFunction $ takeExtension path
116118 sectionFunctions = map (readSection renderFunction)
117119 (True : repeat False)
@@ -128,11 +130,19 @@ readPage path = do
128130 ] ++ context
129131
130132 seq (($|) id rdeepseq context) $ liftIO $ hClose handle
131−
132133 return page
133134 where
134135 url = toURL path
135136
137+-- | Read a page. Might fetch it from the cache if available.
138+readPage :: FilePath -> Hakyll Page
139+readPage path = do
140+ cacheResult <- getFromCache path
141+ case cacheResult of (Just page) -> return page
142+ Nothing -> do page <- readPageFromFile path
143+ storeInCache page path
144+ return page
145+
136146-- Make pages renderable.
137147instance Renderable Page where
138148 getDependencies = (:[]) . getPagePath