diff options
Diffstat (limited to 'src/Hakyll/Web/Util/String.hs')
-rw-r--r-- | src/Hakyll/Web/Util/String.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Util/String.hs b/src/Hakyll/Web/Util/String.hs index 5a8c7c6..e48580b 100644 --- a/src/Hakyll/Web/Util/String.hs +++ b/src/Hakyll/Web/Util/String.hs @@ -2,13 +2,25 @@ -- module Hakyll.Web.Util.String ( trim + , toSiteRoot ) where import Data.Char (isSpace) +import System.FilePath (splitPath, takeDirectory, joinPath) + -- | Trim a string (drop spaces, tabs and newlines at both sides). -- trim :: String -> String trim = reverse . trim' . reverse . trim' where trim' = dropWhile isSpace + +-- | Get the relative url to the site root, for a given (absolute) url +-- +toSiteRoot :: FilePath -> FilePath +toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory + where + parent = const ".." + emptyException [] = "." + emptyException x = x |