@@ -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')