@@ -18,6 +18,7 @@ import System.IO
19import Text.Pandoc
19import Text.Pandoc
21+import Text.Hakyll.Internal.Cache
21import Text.Hakyll.Hakyll (Hakyll)
22import Text.Hakyll.Hakyll (Hakyll)
22import Text.Hakyll.File
23import Text.Hakyll.File
23import Text.Hakyll.Util (trim)
24import Text.Hakyll.Util (trim)
@@ -28,6 +29,7 @@ import Text.Hakyll.Regex (substituteRegex, matchesRegex)
28-- | A Page is basically key-value mapping. Certain keys have special
29-- | A Page is basically key-value mapping. Certain keys have special
29-- meanings, like for example url, body and title.
30-- meanings, like for example url, body and title.
30data Page = Page Context
31data Page = Page Context
32+ deriving (Show, Read)
32-- | Create a Page from a key-value mapping.
34-- | Create a Page from a key-value mapping.
33fromContext :: Context -> Page
35fromContext :: Context -> Page
@@ -110,8 +112,8 @@ readSection renderFunction isFirst ls
111-- | Read a page from a file. Metadata is supported, and if the filename
113-- | Read a page from a file. Metadata is supported, and if the filename
112-- has a @.markdown@ extension, it will be rendered using pandoc.
114-- has a @.markdown@ extension, it will be rendered using pandoc.
113−readPage :: FilePath -> Hakyll Page
115+readPageFromFile :: FilePath -> Hakyll Page
114−readPage path = do
116+readPageFromFile path = do
115 let renderFunction = getRenderFunction $ takeExtension path
117 let renderFunction = getRenderFunction $ takeExtension path
116 sectionFunctions = map (readSection renderFunction)
118 sectionFunctions = map (readSection renderFunction)
117 (True : repeat False)
119 (True : repeat False)
@@ -128,11 +130,19 @@ readPage path = do
128 ] ++ context
130 ] ++ context
130 seq (($|) id rdeepseq context) $ liftIO $ hClose handle
132 seq (($|) id rdeepseq context) $ liftIO $ hClose handle
132 return page
133 return page
134 url = toURL path
135 url = toURL path
137+-- | Read a page. Might fetch it from the cache if available.
138+readPage :: FilePath -> Hakyll Page
140+ cacheResult <- getFromCache path
141+ case cacheResult of (Just page) -> return page
142+ Nothing -> do page <- readPageFromFile path
143+ storeInCache page path
136-- Make pages renderable.
146-- Make pages renderable.
137instance Renderable Page where
147instance Renderable Page where
138 getDependencies = (:[]) . getPagePath
148 getDependencies = (:[]) . getPagePath