on master help sign in
Removed page caching.

I am removing page caching for the following reasons (in no particular order): - It is very error-prone because the pandoc output might interfere with the Hakyll page layout (and thus would pages be read incorrectly). - Timestamping is a much better method to save compilation time. - It would also mess up Unicode sometimes. - Hakyll is aimed at small to medium sites. This caching would not bring a huge speedup anyway. Note: there still is timestamp checking!

commit68facf83ec0c223b9c033cc632041d45732ab0e7 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 19 Jan 2010, 16:34 (17 years ago) parentfe77089
3 files changed+10−47
src/Text/Hakyll.hs+1−2 src/Text/Hakyll/File.hs−5 src/Text/Hakyll/Page.hs+9−40
src/Text/Hakyll.hs+1−2
@@ -39,8 +39,7 @@ build configuration buildFunction = do putStrLn "Generating..."
3939
4040-- | Clean up directories.
4141clean :: IO ()
42−clean = do remove' "_cache"
43− remove' "_site"
42+clean = remove' "_site"
4443 where
4544 remove' dir = do putStrLn $ "Removing " ++ dir ++ "..."
4645 exists <- doesDirectoryExist dir
src/Text/Hakyll/File.hs−5
@@ -2,7 +2,6 @@
22-- files and directories.
33module Text.Hakyll.File
44 ( toDestination
5− , toCache
65 , toURL
76 , toRoot
87 , removeSpaces
@@ -36,10 +35,6 @@ removeLeadingSeparator path
3635toDestination :: FilePath -> FilePath
3736toDestination path = "_site" </> removeLeadingSeparator path
3837
39−-- | Convert a relative filepath to a filepath in the cache (@_cache@).
40−toCache :: FilePath -> FilePath
41−toCache path = "_cache" </> removeLeadingSeparator path
42−
4338-- | Get the url for a given page.
4439toURL :: FilePath -> FilePath
4540toURL path = if takeExtension path `elem` [ ".markdown"
src/Text/Hakyll/Page.hs+9−40
@@ -4,15 +4,15 @@ module Text.Hakyll.Page
44 , getValue
55 , getBody
66 , readPage
7+ , splitAtDelimiters
78 ) where
89
910import qualified Data.Map as M
10−import qualified Data.List as L
11+import Data.List (isPrefixOf)
1112import Data.Char (isSpace)
1213import Data.Maybe (fromMaybe)
1314import Control.Parallel.Strategies (rdeepseq, ($|))
1415import Control.Monad.Reader (liftIO)
15−import Control.Monad (unless)
1616import System.FilePath (takeExtension)
1717import System.IO
1818
@@ -81,33 +81,7 @@ splitAtDelimiters ls@(x:xs)
8181
8282-- | Check if the given string is a metadata delimiter.
8383isDelimiter :: String -> Bool
84−isDelimiter = L.isPrefixOf "---"
85−
86−-- | Used for caching of files.
87−cachePage :: Page -> Hakyll ()
88−cachePage page@(Page mapping) = do
89− makeDirectories destination
90− liftIO writePageToCache
91− where
92− (sectionMetaData, simpleMetaData) = M.partition (elem '\n')
93− (M.delete "body" mapping)
94−
95− writePageToCache = do
96− handle <- openFile destination WriteMode
97− hPutStrLn handle "---"
98− mapM_ (writePair handle) $ M.toList simpleMetaData
99− mapM_ (writeSection handle) $ M.toList sectionMetaData
100− hPutStrLn handle "---"
101− hPutStrLn handle $ getBody page
102− hClose handle
103−
104− writePair h (k, v) = do hPutStr h $ k ++ ": " ++ v
105− hPutStrLn h ""
106−
107− writeSection h (k, v) = do hPutStrLn h $ "--- " ++ k
108− hPutStrLn h v
109−
110− destination = toCache $ getURL page
84+isDelimiter = isPrefixOf "---"
11185
11286-- | Read one section of a page.
11387readSection :: (String -> String) -- ^ Render function.
@@ -122,7 +96,7 @@ readSection renderFunction isFirst ls
12296 | otherwise = body (tail ls)
12397 where
12498 isDelimiter' = isDelimiter (head ls)
125− isNamedDelimiter = head ls `matchesRegex` "----* *[a-zA-Z0-9][a-zA-Z0-9]*"
99+ isNamedDelimiter = head ls `matchesRegex` "^----* *[a-zA-Z0-9][a-zA-Z0-9]*"
126100 body ls' = [("body", renderFunction $ unlines ls')]
127101
128102 readSimpleMetaData = map readPair . filter (not . all isSpace)
@@ -137,11 +111,8 @@ readSection renderFunction isFirst ls
137111-- | Read a page from a file. Metadata is supported, and if the filename
138112-- has a @.markdown@ extension, it will be rendered using pandoc.
139113readPage :: FilePath -> Hakyll Page
140−readPage pagePath = do
141− -- Check cache.
142− getFromCache <- isCacheValid cacheFile [pagePath]
143− let path = if getFromCache then cacheFile else pagePath
144− renderFunction = getRenderFunction $ takeExtension path
114+readPage path = do
115+ let renderFunction = getRenderFunction $ takeExtension path
145116 sectionFunctions = map (readSection renderFunction)
146117 (True : repeat False)
147118
@@ -149,21 +120,19 @@ readPage pagePath = do
149120 handle <- liftIO $ openFile path ReadMode
150121 sections <- fmap (splitAtDelimiters . lines )
151122 (liftIO $ hGetContents handle)
123+ liftIO $ print sections
152124
153125 let context = concat $ zipWith ($) sectionFunctions sections
154126 page = fromContext $ M.fromList $
155127 [ ("url", url)
156− , ("path", pagePath)
128+ , ("path", path)
157129 ] ++ context
158130
159131 seq (($|) id rdeepseq context) $ liftIO $ hClose handle
160132
161− -- Cache if needed
162− unless getFromCache $ cachePage page
163133 return page
164134 where
165− url = toURL pagePath
166− cacheFile = toCache url
135+ url = toURL path
167136
168137-- Make pages renderable.
169138instance Renderable Page where