summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Util/Url.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-28 22:33:28 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-28 22:33:28 +0100
commit49989eab5767b24cb3e917b95137ae05566e34a8 (patch)
tree30a7cde43237c89660511129106ac0b5c87504ac /src/Hakyll/Web/Util/Url.hs
parentc355b047db5dfb479c83c13474f02cb83fe83e96 (diff)
downloadhakyll-49989eab5767b24cb3e917b95137ae05566e34a8.tar.gz
Web.Util.String → {Web.Util.Url, Core.Util.String}
Diffstat (limited to 'src/Hakyll/Web/Util/Url.hs')
-rw-r--r--src/Hakyll/Web/Util/Url.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Util/Url.hs b/src/Hakyll/Web/Util/Url.hs
new file mode 100644
index 0000000..54a361e
--- /dev/null
+++ b/src/Hakyll/Web/Util/Url.hs
@@ -0,0 +1,30 @@
+-- | Miscellaneous URL manipulation functions.
+--
+module Hakyll.Web.Util.Url
+ ( toUrl
+ , toSiteRoot
+ ) where
+
+import System.FilePath (splitPath, takeDirectory, joinPath)
+
+-- | Convert a filepath to an URL starting from the site root
+--
+-- Example:
+--
+-- > toUrl "foo/bar.html"
+--
+-- Result:
+--
+-- > "/foo/bar.html"
+--
+toUrl :: FilePath -> String
+toUrl = ('/' :)
+
+-- | Get the relative url to the site root, for a given (absolute) url
+--
+toSiteRoot :: String -> String
+toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory
+ where
+ parent = const ".."
+ emptyException [] = "."
+ emptyException x = x