summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-28 22:40:23 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-28 22:40:23 +0100
commitd460fd88d13984aa0e851527f7ff65065230c411 (patch)
tree15dd7f4444743ecae78abad8ce7d20ba71ee9258 /src
parent49989eab5767b24cb3e917b95137ae05566e34a8 (diff)
downloadhakyll-d460fd88d13984aa0e851527f7ff65065230c411.tar.gz
Add `gsubRoute`
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Core/Routes.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Hakyll/Core/Routes.hs b/src/Hakyll/Core/Routes.hs
index 250536a..eba35ff 100644
--- a/src/Hakyll/Core/Routes.hs
+++ b/src/Hakyll/Core/Routes.hs
@@ -32,6 +32,7 @@ module Hakyll.Core.Routes
, setExtension
, ifMatch
, customRoute
+ , gsubRoute
) where
import Data.Monoid (Monoid, mempty, mappend)
@@ -40,6 +41,7 @@ import System.FilePath (replaceExtension)
import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
+import Hakyll.Core.Util.String
-- | Type used for a route
--
@@ -94,3 +96,19 @@ ifMatch pattern (Routes route) = Routes $ \id' ->
--
customRoute :: (Identifier -> FilePath) -> Routes
customRoute f = Routes $ Just . f
+
+-- | Create a gsub route
+--
+-- Example:
+--
+-- > runRoutes (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
+--
+-- Result:
+--
+-- > Just "tags/bar.xml"
+--
+gsubRoute :: String -- ^ Pattern
+ -> (String -> String) -- ^ Replacement
+ -> Routes -- ^ Resulting route
+gsubRoute pattern replacement = customRoute $
+ replaceAll pattern replacement . toFilePath