From 877cb21d1630d32c6e40eb7c6f0ecc7e1da2bd52 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 18 Nov 2012 21:56:52 +0100 Subject: Add Item abstraction --- src/Hakyll/Web/Urls/Relativize.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Hakyll/Web/Urls') diff --git a/src/Hakyll/Web/Urls/Relativize.hs b/src/Hakyll/Web/Urls/Relativize.hs index 068ae09..321bbe3 100644 --- a/src/Hakyll/Web/Urls/Relativize.hs +++ b/src/Hakyll/Web/Urls/Relativize.hs @@ -15,8 +15,8 @@ -- -- > Funny zomgroflcopter module Hakyll.Web.Urls.Relativize - ( relativizeUrlsCompiler - , relativizeUrls + ( relativizeUrls + , relativizeUrlsWith ) where @@ -26,27 +26,27 @@ import Data.List (isPrefixOf) -------------------------------------------------------------------------------- import Hakyll.Core.Compiler -import Hakyll.Web.Page +import Hakyll.Core.Item import Hakyll.Web.Urls -------------------------------------------------------------------------------- -- | Compiler form of 'relativizeUrls' which automatically picks the right root -- path -relativizeUrlsCompiler :: Page -> Compiler Page -relativizeUrlsCompiler page = do - route <- getRoute +relativizeUrls :: Item String -> Compiler (Item String) +relativizeUrls item = do + route <- getRoute $ itemIdentifier item return $ case route of - Nothing -> page - Just r -> relativizeUrls (toSiteRoot r) page + Nothing -> item + Just r -> fmap (relativizeUrlsWith $ toSiteRoot r) item -------------------------------------------------------------------------------- -- | Relativize URL's in HTML -relativizeUrls :: String -- ^ Path to the site root - -> Page -- ^ HTML to relativize - -> Page -- ^ Resulting HTML -relativizeUrls root = withUrls rel +relativizeUrlsWith :: String -- ^ Path to the site root + -> String -- ^ HTML to relativize + -> String -- ^ Resulting HTML +relativizeUrlsWith root = withUrls rel where isRel x = "/" `isPrefixOf` x && not ("//" `isPrefixOf` x) rel x = if isRel x then root ++ x else x -- cgit v1.2.3