on master help sign in
More granular dependencies for routes
8f53440Jasper Van der Jeugt
src/Hakyll/Core/Compiler.hs+4−2
@@ -29,6 +29,7 @@ module Hakyll.Core.Compiler
29
29
30--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
31import Control.Applicative ((<$>))
31import Control.Applicative ((<$>))
32+import Control.Monad (when)
32import Data.Binary (Binary)
33import Data.Binary (Binary)
33import Data.ByteString.Lazy (ByteString)
34import Data.ByteString.Lazy (ByteString)
34import Data.Typeable (Typeable)
35import Data.Typeable (Typeable)
@@ -76,8 +77,9 @@ getRoute identifier = do
76 routes <- compilerRoutes <$> compilerAsk
77 routes <- compilerRoutes <$> compilerAsk
77 -- Note that this makes us dependend on that identifier: when the metadata
78 -- Note that this makes us dependend on that identifier: when the metadata
78 -- of that item changes, the route may change, hence we have to recompile
79 -- of that item changes, the route may change, hence we have to recompile
80+ (mfp, um) <- compilerUnsafeIO $ runRoutes routes provider identifier
79− compilerTellDependencies [IdentifierDependency identifier]
81+ when um $ compilerTellDependencies [IdentifierDependency identifier]
80− compilerUnsafeIO $ runRoutes routes provider identifier
82+ return mfp
81
83
82
84
83--------------------------------------------------------------------------------
85--------------------------------------------------------------------------------
src/Hakyll/Core/Routes.hs+24−10
@@ -27,7 +27,8 @@
27-- * If an item matches multiple routes, the first rule will be chosen.
27-- * If an item matches multiple routes, the first rule will be chosen.
28{-# LANGUAGE Rank2Types #-}
28{-# LANGUAGE Rank2Types #-}
29module Hakyll.Core.Routes
29module Hakyll.Core.Routes
30+ ( UsedMetadata
30− ( Routes
31+ , Routes
31 , runRoutes
32 , runRoutes
32 , idRoute
33 , idRoute
33 , setExtension
34 , setExtension
@@ -53,24 +54,33 @@ import Hakyll.Core.Provider
53import Hakyll.Core.Util.String
54import Hakyll.Core.Util.String
54
55
55
56
57+--------------------------------------------------------------------------------
58+-- | When you ran a route, it's useful to know whether or not this used
59+-- metadata. This allows us to do more granular dependency analysis.
60+type UsedMetadata = Bool
61+
62+
56--------------------------------------------------------------------------------
63--------------------------------------------------------------------------------
57-- | Type used for a route
64-- | Type used for a route
58newtype Routes = Routes
65newtype Routes = Routes
59− { unRoutes :: Provider -> Identifier -> IO (Maybe FilePath)
66+ { unRoutes :: Provider -> Identifier -> IO (Maybe FilePath, UsedMetadata)
60 }
67 }
61
68
62
69
63--------------------------------------------------------------------------------
70--------------------------------------------------------------------------------
64instance Monoid Routes where
71instance Monoid Routes where
65− mempty = Routes $ \_ _ -> return Nothing
72+ mempty = Routes $ \_ _ -> return (Nothing, False)
66 mappend (Routes f) (Routes g) = Routes $ \p id' -> do
73 mappend (Routes f) (Routes g) = Routes $ \p id' -> do
67− mfp <- f p id'
74+ (mfp, um) <- f p id'
68− maybe (g p id') (return . Just) mfp
75+ case mfp of
76+ Nothing -> g p id'
77+ Just _ -> return (mfp, um)
69
78
70
79
71--------------------------------------------------------------------------------
80--------------------------------------------------------------------------------
72-- | Apply a route to an identifier
81-- | Apply a route to an identifier
73−runRoutes :: Routes -> Provider -> Identifier -> IO (Maybe FilePath)
82+runRoutes :: Routes -> Provider -> Identifier
83+ -> IO (Maybe FilePath, UsedMetadata)
74runRoutes = unRoutes
84runRoutes = unRoutes
75
85
76
86
@@ -109,14 +119,14 @@ setExtension extension = customRoute $
109-- otherwise
119-- otherwise
110matchRoute :: Pattern -> Routes -> Routes
120matchRoute :: Pattern -> Routes -> Routes
111matchRoute pattern (Routes route) = Routes $ \p id' ->
121matchRoute pattern (Routes route) = Routes $ \p id' ->
112− if matches pattern id' then route p id' else return Nothing
122+ if matches pattern id' then route p id' else return (Nothing, False)
113
123
114
124
115--------------------------------------------------------------------------------
125--------------------------------------------------------------------------------
116-- | Create a custom route. This should almost always be used with
126-- | Create a custom route. This should almost always be used with
117-- 'matchRoute'
127-- 'matchRoute'
118customRoute :: (Identifier -> FilePath) -> Routes
128customRoute :: (Identifier -> FilePath) -> Routes
119−customRoute f = Routes $ const $ return . Just . f
129+customRoute f = Routes $ const $ \id' -> return (Just (f id'), False)
120
130
121
131
122--------------------------------------------------------------------------------
132--------------------------------------------------------------------------------
@@ -169,5 +179,9 @@ composeRoutes :: Routes -- ^ First route to apply
169 -> Routes -- ^ Second route to apply
179 -> Routes -- ^ Second route to apply
170 -> Routes -- ^ Resulting route
180 -> Routes -- ^ Resulting route
171composeRoutes (Routes f) (Routes g) = Routes $ \p i -> do
181composeRoutes (Routes f) (Routes g) = Routes $ \p i -> do
172− mfp <- f p i
182+ (mfp, um) <- f p i
183+ case mfp of
184+ Nothing -> return (Nothing, um)
185+ Just fp -> do
173− maybe (return Nothing) (g p . fromFilePath) mfp
186+ (mfp', um') <- g p (fromFilePath fp)
187+ return (mfp', um || um')
src/Hakyll/Core/Runtime.hs+1−1
@@ -221,7 +221,7 @@ chase trail id'
221 "(you probably want to call makeItem to solve this problem)"
221 "(you probably want to call makeItem to solve this problem)"
222
222
223 -- Write if necessary
223 -- Write if necessary
224− mroute <- liftIO $ runRoutes routes provider id'
224+ (mroute, _) <- liftIO $ runRoutes routes provider id'
225 case mroute of
225 case mroute of
226 Nothing -> return ()
226 Nothing -> return ()
227 Just route -> do
227 Just route -> do