From d460fd88d13984aa0e851527f7ff65065230c411 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 28 Feb 2011 22:40:23 +0100 Subject: Add `gsubRoute` --- src/Hakyll/Core/Routes.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') 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 -- cgit v1.2.3