on 686de03 help sign in
hakyll/src/Hakyll/Web/Util/String.hs
26 lines 663 B history raw
1-- | Miscellaneous string manipulation functions.
2--
3module Hakyll.Web.Util.String
4 ( trim
5 , toSiteRoot
6 ) where
8import Data.Char (isSpace)
10import System.FilePath (splitPath, takeDirectory, joinPath)
12-- | Trim a string (drop spaces, tabs and newlines at both sides).
13--
14trim :: String -> String
15trim = reverse . trim' . reverse . trim'
16 where
17 trim' = dropWhile isSpace
19-- | Get the relative url to the site root, for a given (absolute) url
20--
21toSiteRoot :: FilePath -> FilePath
22toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory
23 where
24 parent = const ".."
25 emptyException [] = "."
26 emptyException x = x