summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-01 09:40:07 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-01 09:40:07 +0100
commitfa057f30117e02f13f4a788eb3f52660ab8ab440 (patch)
treeec958d9a6cee07a52d6bbacdfefbd08533a5625a /src/Hakyll/Core
parentd460fd88d13984aa0e851527f7ff65065230c411 (diff)
downloadhakyll-fa057f30117e02f13f4a788eb3f52660ab8ab440.tar.gz
Add `composeRoutes`
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r--src/Hakyll/Core/Routes.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Routes.hs b/src/Hakyll/Core/Routes.hs
index eba35ff..fcab28d 100644
--- a/src/Hakyll/Core/Routes.hs
+++ b/src/Hakyll/Core/Routes.hs
@@ -33,6 +33,7 @@ module Hakyll.Core.Routes
, ifMatch
, customRoute
, gsubRoute
+ , composeRoutes
) where
import Data.Monoid (Monoid, mempty, mappend)
@@ -112,3 +113,24 @@ gsubRoute :: String -- ^ Pattern
-> Routes -- ^ Resulting route
gsubRoute pattern replacement = customRoute $
replaceAll pattern replacement . toFilePath
+
+-- | Compose routes so that @f `composeRoutes` g@ is more or less equivalent
+-- with @f >>> g@.
+--
+-- Example:
+--
+-- > let routes = gsubRoute "rss/" (const "") `composeRoutes` setExtension "xml"
+-- > in runRoutes routes "tags/rss/bar"
+--
+-- Result:
+--
+-- > Just "tags/bar.xml"
+--
+-- If the first route given fails, Hakyll will not apply the second route.
+--
+composeRoutes :: Routes -- ^ First route to apply
+ -> Routes -- ^ Second route to apply
+ -> Routes -- ^ Resulting route
+composeRoutes (Routes f) (Routes g) = Routes $ \i -> do
+ p <- f i
+ g $ parseIdentifier p