on master help sign in
Removed page caching.
68facf8Jasper Van der Jeugt
src/Text/Hakyll.hs+1−2
@@ -39,8 +39,7 @@ build configuration buildFunction = do putStrLn "Generating..."
39
39
40-- | Clean up directories.
40-- | Clean up directories.
41clean :: IO ()
41clean :: IO ()
42−clean = do remove' "_cache"
43− remove' "_site"
42+clean = remove' "_site"
44 where
43 where
45 remove' dir = do putStrLn $ "Removing " ++ dir ++ "..."
44 remove' dir = do putStrLn $ "Removing " ++ dir ++ "..."
46 exists <- doesDirectoryExist dir
45 exists <- doesDirectoryExist dir
src/Text/Hakyll/File.hs−5
@@ -2,7 +2,6 @@
2-- files and directories.
2-- files and directories.
3module Text.Hakyll.File
3module Text.Hakyll.File
4 ( toDestination
4 ( toDestination
5− , toCache
6 , toURL
5 , toURL
7 , toRoot
6 , toRoot
8 , removeSpaces
7 , removeSpaces
@@ -36,10 +35,6 @@ removeLeadingSeparator path
36toDestination :: FilePath -> FilePath
35toDestination :: FilePath -> FilePath
37toDestination path = "_site" </> removeLeadingSeparator path
36toDestination path = "_site" </> removeLeadingSeparator path
38
37
39−-- | Convert a relative filepath to a filepath in the cache (@_cache@).
40−toCache :: FilePath -> FilePath
41−toCache path = "_cache" </> removeLeadingSeparator path
42−
43-- | Get the url for a given page.
38-- | Get the url for a given page.
44toURL :: FilePath -> FilePath
39toURL :: FilePath -> FilePath
45toURL path = if takeExtension path `elem` [ ".markdown"
40toURL path = if takeExtension path `elem` [ ".markdown"
src/Text/Hakyll/Page.hs+9−40
@@ -4,15 +4,15 @@ module Text.Hakyll.Page
4 , getValue
4 , getValue
5 , getBody
5 , getBody
6 , readPage
6 , readPage
7+ , splitAtDelimiters
7 ) where
8 ) where
8
9
9import qualified Data.Map as M
10import qualified Data.Map as M
10−import qualified Data.List as L
11+import Data.List (isPrefixOf)
11import Data.Char (isSpace)
12import Data.Char (isSpace)
12import Data.Maybe (fromMaybe)
13import Data.Maybe (fromMaybe)
13import Control.Parallel.Strategies (rdeepseq, ($|))
14import Control.Parallel.Strategies (rdeepseq, ($|))
14import Control.Monad.Reader (liftIO)
15import Control.Monad.Reader (liftIO)
15−import Control.Monad (unless)
16import System.FilePath (takeExtension)
16import System.FilePath (takeExtension)
17import System.IO
17import System.IO
18
18
@@ -81,33 +81,7 @@ splitAtDelimiters ls@(x:xs)
81
81
82-- | Check if the given string is a metadata delimiter.
82-- | Check if the given string is a metadata delimiter.
83isDelimiter :: String -> Bool
83isDelimiter :: String -> Bool
84−isDelimiter = L.isPrefixOf "---"
84+isDelimiter = 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
111
85
112-- | Read one section of a page.
86-- | Read one section of a page.
113readSection :: (String -> String) -- ^ Render function.
87readSection :: (String -> String) -- ^ Render function.
@@ -122,7 +96,7 @@ readSection renderFunction isFirst ls
122 | otherwise = body (tail ls)
96 | otherwise = body (tail ls)
123 where
97 where
124 isDelimiter' = isDelimiter (head ls)
98 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]*"
126 body ls' = [("body", renderFunction $ unlines ls')]
100 body ls' = [("body", renderFunction $ unlines ls')]
127
101
128 readSimpleMetaData = map readPair . filter (not . all isSpace)
102 readSimpleMetaData = map readPair . filter (not . all isSpace)
@@ -137,11 +111,8 @@ readSection renderFunction isFirst ls
137-- | Read a page from a file. Metadata is supported, and if the filename
111-- | Read a page from a file. Metadata is supported, and if the filename
138-- has a @.markdown@ extension, it will be rendered using pandoc.
112-- has a @.markdown@ extension, it will be rendered using pandoc.
139readPage :: FilePath -> Hakyll Page
113readPage :: FilePath -> Hakyll Page
140−readPage pagePath = do
114+readPage path = do
141− -- Check cache.
142− getFromCache <- isCacheValid cacheFile [pagePath]
143− let path = if getFromCache then cacheFile else pagePath
144− renderFunction = getRenderFunction $ takeExtension path
115+ let renderFunction = getRenderFunction $ takeExtension path
145 sectionFunctions = map (readSection renderFunction)
116 sectionFunctions = map (readSection renderFunction)
146 (True : repeat False)
117 (True : repeat False)
147
118
@@ -149,21 +120,19 @@ readPage pagePath = do
149 handle <- liftIO $ openFile path ReadMode
120 handle <- liftIO $ openFile path ReadMode
150 sections <- fmap (splitAtDelimiters . lines )
121 sections <- fmap (splitAtDelimiters . lines )
151 (liftIO $ hGetContents handle)
122 (liftIO $ hGetContents handle)
123+ liftIO $ print sections
152
124
153 let context = concat $ zipWith ($) sectionFunctions sections
125 let context = concat $ zipWith ($) sectionFunctions sections
154 page = fromContext $ M.fromList $
126 page = fromContext $ M.fromList $
155 [ ("url", url)
127 [ ("url", url)
156− , ("path", pagePath)
128+ , ("path", path)
157 ] ++ context
129 ] ++ context
158
130
159 seq (($|) id rdeepseq context) $ liftIO $ hClose handle
131 seq (($|) id rdeepseq context) $ liftIO $ hClose handle
160
132
161− -- Cache if needed
162− unless getFromCache $ cachePage page
163 return page
133 return page
164 where
134 where
165− url = toURL pagePath
135+ url = toURL path
166− cacheFile = toCache url
167
136
168-- Make pages renderable.
137-- Make pages renderable.
169instance Renderable Page where
138instance Renderable Page where