diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-02-28 22:40:23 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-02-28 22:40:23 +0100 |
commit | d460fd88d13984aa0e851527f7ff65065230c411 (patch) | |
tree | 15dd7f4444743ecae78abad8ce7d20ba71ee9258 /src | |
parent | 49989eab5767b24cb3e917b95137ae05566e34a8 (diff) | |
download | hakyll-d460fd88d13984aa0e851527f7ff65065230c411.tar.gz |
Add `gsubRoute`
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Core/Routes.hs | 18 |
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 |