@@ -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
31 , runRoutes
32 , runRoutes
33 , setExtension
34 , setExtension
@@ -53,24 +54,33 @@ import Hakyll.Core.Provider
53import Hakyll.Core.Util.String
54import Hakyll.Core.Util.String
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
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)
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
77+ Just _ -> return (mfp, um)
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
@@ -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)
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)
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
184+ Nothing -> return (Nothing, um)
173− maybe (return Nothing) (g p . fromFilePath) mfp
186+ (mfp', um') <- g p (fromFilePath fp)
187+ return (mfp', um || um')