on master help sign in
Work on migration to arrows. Compulation fails.
192c4a1Jasper Van der Jeugt
hakyll.cabal+1−1
@@ -47,11 +47,11 @@ library
47 Text.Hakyll.RenderAction
47 Text.Hakyll.RenderAction
48 Text.Hakyll.Renderable
48 Text.Hakyll.Renderable
49 Text.Hakyll.Renderables
49 Text.Hakyll.Renderables
50− Text.Hakyll.Page
51 Text.Hakyll.Paginate
50 Text.Hakyll.Paginate
52 Text.Hakyll.Util
51 Text.Hakyll.Util
53 Text.Hakyll.Tags
52 Text.Hakyll.Tags
54 Text.Hakyll.Internal.Cache
53 Text.Hakyll.Internal.Cache
55 Text.Hakyll.Internal.CompressCss
54 Text.Hakyll.Internal.CompressCss
55+ Text.Hakyll.Internal.Page
56 Text.Hakyll.Internal.Render
56 Text.Hakyll.Internal.Render
57 Text.Hakyll.Internal.Template
57 Text.Hakyll.Internal.Template
src/Text/Hakyll/Page.hs → src/Text/Hakyll/Internal/Page.hsrenamed+8−12
@@ -1,5 +1,5 @@
1-- | A module for dealing with @Page@s. This module is mostly internally used.
1-- | A module for dealing with @Page@s. This module is mostly internally used.
2−module Text.Hakyll.Page
2+module Text.Hakyll.Internal.Page
3 ( Page
3 ( Page
4 , fromContext
4 , fromContext
5 , getValue
5 , getValue
@@ -25,6 +25,7 @@ import Text.Hakyll.File
25import Text.Hakyll.Util (trim)
25import Text.Hakyll.Util (trim)
26import Text.Hakyll.Context (Context)
26import Text.Hakyll.Context (Context)
27import Text.Hakyll.Renderable
27import Text.Hakyll.Renderable
28+import Text.Hakyll.RenderAction
28import Text.Hakyll.Regex (substituteRegex, matchesRegex)
29import Text.Hakyll.Regex (substituteRegex, matchesRegex)
29
30
30-- | A Page is basically key-value mapping. Certain keys have special
31-- | A Page is basically key-value mapping. Certain keys have special
@@ -125,7 +126,7 @@ readSection renderFunction isFirst ls
125
126
126-- | Read a page from a file. Metadata is supported, and if the filename
127-- | Read a page from a file. Metadata is supported, and if the filename
127-- has a @.markdown@ extension, it will be rendered using pandoc.
128-- has a @.markdown@ extension, it will be rendered using pandoc.
128−readPageFromFile :: FilePath -> Hakyll Page
129+readPageFromFile :: FilePath -> Hakyll Context
129readPageFromFile path = do
130readPageFromFile path = do
130 let renderFunction = getRenderFunction $ takeExtension path
131 let renderFunction = getRenderFunction $ takeExtension path
131 sectionFunctions = map (readSection renderFunction)
132 sectionFunctions = map (readSection renderFunction)
@@ -133,23 +134,18 @@ readPageFromFile path = do
133
134
134 -- Read file.
135 -- Read file.
135 contents <- liftIO $ readFile path
136 contents <- liftIO $ readFile path
136− url <- toUrl path
137 let sections = splitAtDelimiters $ lines contents
137 let sections = splitAtDelimiters $ lines contents
138− context = concat $ zipWith ($) sectionFunctions sections
138+ sectionsData = concat $ zipWith ($) sectionFunctions sections
139− page = fromContext $ M.fromList $
139+ context = M.fromList $ category ++ sectionsData
140− category ++
140+
141− [ ("url", url)
142− , ("path", path)
143− ] ++ context
144−
145− return page
141+ return context
146 where
142 where
147 category = let dirs = splitDirectories $ takeDirectory path
143 category = let dirs = splitDirectories $ takeDirectory path
148 in [("category", last dirs) | not (null dirs)]
144 in [("category", last dirs) | not (null dirs)]
149
145
150-- | Read a page. Might fetch it from the cache if available. Otherwise, it will
146-- | Read a page. Might fetch it from the cache if available. Otherwise, it will
151-- read it from the file given and store it in the cache.
147-- read it from the file given and store it in the cache.
152−readPage :: FilePath -> Hakyll Page
148+readPage :: FilePath -> Hakyll Context
153readPage path = do
149readPage path = do
154 isCacheMoreRecent' <- isCacheMoreRecent fileName [path]
150 isCacheMoreRecent' <- isCacheMoreRecent fileName [path]
155 if isCacheMoreRecent' then getFromCache fileName
151 if isCacheMoreRecent' then getFromCache fileName
src/Text/Hakyll/Internal/Render.hs+1−1
@@ -16,9 +16,9 @@ import Data.Maybe (fromMaybe)
16
16
17import Text.Hakyll.Context (Context, ContextManipulation)
17import Text.Hakyll.Context (Context, ContextManipulation)
18import Text.Hakyll.Renderable
18import Text.Hakyll.Renderable
19−import Text.Hakyll.Page
20import Text.Hakyll.File
19import Text.Hakyll.File
21import Text.Hakyll.Hakyll
20import Text.Hakyll.Hakyll
21+import Text.Hakyll.Internal.Page
22import Text.Hakyll.Internal.Template
22import Text.Hakyll.Internal.Template
23
23
24-- | A pure render function.
24-- | A pure render function.
src/Text/Hakyll/Render.hs+2−2
@@ -18,12 +18,12 @@ import System.Directory (copyFile)
18
18
19import Text.Hakyll.Hakyll (Hakyll)
19import Text.Hakyll.Hakyll (Hakyll)
20import Text.Hakyll.Context (ContextManipulation)
20import Text.Hakyll.Context (ContextManipulation)
21−import Text.Hakyll.Page
22import Text.Hakyll.Renderable
21import Text.Hakyll.Renderable
23import Text.Hakyll.File
22import Text.Hakyll.File
24−import Text.Hakyll.Internal.Template (readTemplate)
25import Text.Hakyll.Internal.CompressCss
23import Text.Hakyll.Internal.CompressCss
24+import Text.Hakyll.Internal.Page
26import Text.Hakyll.Internal.Render
25import Text.Hakyll.Internal.Render
26+import Text.Hakyll.Internal.Template (readTemplate)
27
27
28-- | Execute an IO action only when the cache is invalid.
28-- | Execute an IO action only when the cache is invalid.
29depends :: FilePath -- ^ File to be rendered or created.
29depends :: FilePath -- ^ File to be rendered or created.
src/Text/Hakyll/Renderables.hs+8−15
@@ -11,18 +11,18 @@ module Text.Hakyll.Renderables
11
11
12import qualified Data.Map as M
12import qualified Data.Map as M
13import Control.Arrow (second)
13import Control.Arrow (second)
14−import Control.Monad (liftM, liftM2, mplus)
14+import Control.Monad (liftM2, mplus)
15import Control.Applicative ((<$>))
15import Control.Applicative ((<$>))
16
16
17import Data.Binary
17import Data.Binary
18
18
19import Text.Hakyll.Hakyll (Hakyll)
19import Text.Hakyll.Hakyll (Hakyll)
20−import Text.Hakyll.Page
21import Text.Hakyll.Renderable
20import Text.Hakyll.Renderable
22import Text.Hakyll.File
21import Text.Hakyll.File
23import Text.Hakyll.Context
22import Text.Hakyll.Context
24import Text.Hakyll.Render
23import Text.Hakyll.Render
25import Text.Hakyll.RenderAction
24import Text.Hakyll.RenderAction
25+import Text.Hakyll.Internal.Page
26
26
27-- | Create a custom page.
27-- | Create a custom page.
28--
28--
@@ -90,19 +90,12 @@ newtype PagePath = PagePath FilePath
90 deriving (Ord, Eq, Read, Show)
90 deriving (Ord, Eq, Read, Show)
91
91
92-- | Create a PagePath from a FilePath.
92-- | Create a PagePath from a FilePath.
93−createPagePath :: FilePath -> PagePath
93+createPagePath :: FilePath -> RenderAction () Context
94−createPagePath = PagePath
94+createPagePath path = RenderAction
95−
95+ { actionDependencies = [path]
96−-- We can render filepaths
96+ , actionDestination = Just $ toUrl path
97−instance Renderable PagePath where
97+ , actionFunction = const (readPage path)
98− getDependencies (PagePath path) = return path
98+ }
99− getUrl (PagePath path) = toUrl path
100− toContext (PagePath path) = readPage path >>= toContext
101−
102−-- We can serialize filepaths
103−instance Binary PagePath where
104− put (PagePath path) = put path
105− get = liftM PagePath get
106
99
107-- | A combination of two other renderables.
100-- | A combination of two other renderables.
108data CombinedRenderable a b = CombinedRenderable a b
101data CombinedRenderable a b = CombinedRenderable a b