@@ -33,6 +33,7 @@ module Hakyll.Core.Routes
3333 , ifMatch
3434 , customRoute
3535 , gsubRoute
36+ , composeRoutes
3637 ) where
3738
3839import Data.Monoid (Monoid, mempty, mappend)
@@ -112,3 +113,24 @@ gsubRoute :: String -- ^ Pattern
112113 -> Routes -- ^ Resulting route
113114gsubRoute pattern replacement = customRoute $
114115 replaceAll pattern replacement . toFilePath
116+
117+-- | Compose routes so that @f `composeRoutes` g@ is more or less equivalent
118+-- with @f >>> g@.
119+--
120+-- Example:
121+--
122+-- > let routes = gsubRoute "rss/" (const "") `composeRoutes` setExtension "xml"
123+-- > in runRoutes routes "tags/rss/bar"
124+--
125+-- Result:
126+--
127+-- > Just "tags/bar.xml"
128+--
129+-- If the first route given fails, Hakyll will not apply the second route.
130+--
131+composeRoutes :: Routes -- ^ First route to apply
132+ -> Routes -- ^ Second route to apply
133+ -> Routes -- ^ Resulting route
134+composeRoutes (Routes f) (Routes g) = Routes $ \i -> do
135+ p <- f i
136+ g $ parseIdentifier p