on master help sign in
More granular dependencies for routes

See #121

commit8f534400be335958fb67f558ce2d378509ae4d48 authorJasper Van der Jeugt <m@jaspervdj.be> dateFri 3 May 2013, 11:03 (13 years ago) parent9a75bba
3 files changed+29−13
src/Hakyll/Core/Compiler.hs+4−2 src/Hakyll/Core/Routes.hs+24−10 src/Hakyll/Core/Runtime.hs+1−1
src/Hakyll/Core/Compiler.hs+4−2
@@ -29,6 +29,7 @@ module Hakyll.Core.Compiler
2929
3030--------------------------------------------------------------------------------
3131import Control.Applicative ((<$>))
32+import Control.Monad (when)
3233import Data.Binary (Binary)
3334import Data.ByteString.Lazy (ByteString)
3435import Data.Typeable (Typeable)
@@ -76,8 +77,9 @@ getRoute identifier = do
7677 routes <- compilerRoutes <$> compilerAsk
7778 -- Note that this makes us dependend on that identifier: when the metadata
7879 -- of that item changes, the route may change, hence we have to recompile
79− compilerTellDependencies [IdentifierDependency identifier]
80− compilerUnsafeIO $ runRoutes routes provider identifier
80+ (mfp, um) <- compilerUnsafeIO $ runRoutes routes provider identifier
81+ when um $ compilerTellDependencies [IdentifierDependency identifier]
82+ return mfp
8183
8284
8385--------------------------------------------------------------------------------
src/Hakyll/Core/Routes.hs+24−10
@@ -27,7 +27,8 @@
2727-- * If an item matches multiple routes, the first rule will be chosen.
2828{-# LANGUAGE Rank2Types #-}
2929module Hakyll.Core.Routes
30− ( Routes
30+ ( UsedMetadata
31+ , Routes
3132 , runRoutes
3233 , idRoute
3334 , setExtension
@@ -53,24 +54,33 @@ import Hakyll.Core.Provider
5354import Hakyll.Core.Util.String
5455
5556
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+
5663--------------------------------------------------------------------------------
5764-- | Type used for a route
5865newtype Routes = Routes
59− { unRoutes :: Provider -> Identifier -> IO (Maybe FilePath)
66+ { unRoutes :: Provider -> Identifier -> IO (Maybe FilePath, UsedMetadata)
6067 }
6168
6269
6370--------------------------------------------------------------------------------
6471instance Monoid Routes where
65− mempty = Routes $ \_ _ -> return Nothing
72+ mempty = Routes $ \_ _ -> return (Nothing, False)
6673 mappend (Routes f) (Routes g) = Routes $ \p id' -> do
67− mfp <- f p id'
68− maybe (g p id') (return . Just) mfp
74+ (mfp, um) <- f p id'
75+ case mfp of
76+ Nothing -> g p id'
77+ Just _ -> return (mfp, um)
6978
7079
7180--------------------------------------------------------------------------------
7281-- | Apply a route to an identifier
73−runRoutes :: Routes -> Provider -> Identifier -> IO (Maybe FilePath)
82+runRoutes :: Routes -> Provider -> Identifier
83+ -> IO (Maybe FilePath, UsedMetadata)
7484runRoutes = unRoutes
7585
7686
@@ -109,14 +119,14 @@ setExtension extension = customRoute $
109119-- otherwise
110120matchRoute :: Pattern -> Routes -> Routes
111121matchRoute 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)
113123
114124
115125--------------------------------------------------------------------------------
116126-- | Create a custom route. This should almost always be used with
117127-- 'matchRoute'
118128customRoute :: (Identifier -> FilePath) -> Routes
119−customRoute f = Routes $ const $ return . Just . f
129+customRoute f = Routes $ const $ \id' -> return (Just (f id'), False)
120130
121131
122132--------------------------------------------------------------------------------
@@ -169,5 +179,9 @@ composeRoutes :: Routes -- ^ First route to apply
169179 -> Routes -- ^ Second route to apply
170180 -> Routes -- ^ Resulting route
171181composeRoutes (Routes f) (Routes g) = Routes $ \p i -> do
172− mfp <- f p i
173− maybe (return Nothing) (g p . fromFilePath) mfp
182+ (mfp, um) <- f p i
183+ case mfp of
184+ Nothing -> return (Nothing, um)
185+ Just fp -> do
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'
221221 "(you probably want to call makeItem to solve this problem)"
222222
223223 -- Write if necessary
224− mroute <- liftIO $ runRoutes routes provider id'
224+ (mroute, _) <- liftIO $ runRoutes routes provider id'
225225 case mroute of
226226 Nothing -> return ()
227227 Just route -> do