summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-08 11:03:07 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-08 11:03:07 +0100
commitcf71e295467aa75606d491627541610e17dd1c64 (patch)
treec02fc26982520fefb83e21df2fb15de0dd3e5532
parent1ea56781300e47c02ffd0ec055bfeb3539a2e1e1 (diff)
downloadhakyll-cf71e295467aa75606d491627541610e17dd1c64.tar.gz
Make toSiteRoot work with /xxx URL's
-rw-r--r--src/Hakyll/Web/RelativizeUrls.hs2
-rw-r--r--src/Hakyll/Web/Util/Url.hs4
-rw-r--r--tests/Hakyll/Web/Util/Url/Tests.hs25
-rw-r--r--tests/TestSuite.hs3
4 files changed, 32 insertions, 2 deletions
diff --git a/src/Hakyll/Web/RelativizeUrls.hs b/src/Hakyll/Web/RelativizeUrls.hs
index 2de4a0e..06b4ae2 100644
--- a/src/Hakyll/Web/RelativizeUrls.hs
+++ b/src/Hakyll/Web/RelativizeUrls.hs
@@ -31,7 +31,7 @@ import Hakyll.Core.Compiler
import Hakyll.Web.Page
import Hakyll.Web.Util.Url
--- | Compiler form of 'compressCss' which automatically picks the right root
+-- | Compiler form of 'relativizeUrls' which automatically picks the right root
-- path
--
relativizeUrlsCompiler :: Compiler (Page String) (Page String)
diff --git a/src/Hakyll/Web/Util/Url.hs b/src/Hakyll/Web/Util/Url.hs
index 8a02ef3..a0702d8 100644
--- a/src/Hakyll/Web/Util/Url.hs
+++ b/src/Hakyll/Web/Util/Url.hs
@@ -24,8 +24,10 @@ toUrl url = '/' : url
-- | Get the relative url to the site root, for a given (absolute) url
--
toSiteRoot :: String -> String
-toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory
+toSiteRoot = emptyException . joinPath . map parent
+ . splitPath . takeDirectory . dropLeadingSlash
where
parent = const ".."
emptyException [] = "."
emptyException x = x
+ dropLeadingSlash = dropWhile (== '/')
diff --git a/tests/Hakyll/Web/Util/Url/Tests.hs b/tests/Hakyll/Web/Util/Url/Tests.hs
new file mode 100644
index 0000000..aab4172
--- /dev/null
+++ b/tests/Hakyll/Web/Util/Url/Tests.hs
@@ -0,0 +1,25 @@
+module Hakyll.Web.Util.Url.Tests
+ ( tests
+ ) where
+
+import Test.Framework
+import Test.HUnit hiding (Test)
+
+import Hakyll.Web.Util.Url
+import TestSuite.Util
+
+tests :: [Test]
+tests = concat
+ [ fromAssertions "toUrl"
+ [ "/foo/bar.html" @=? toUrl "foo/bar.html"
+ , "/" @=? toUrl "/"
+ , "/funny-pics.html" @=? toUrl "/funny-pics.html"
+ ]
+
+ , fromAssertions "toSiteRoot"
+ [ ".." @=? toSiteRoot "/foo/bar.html"
+ , "." @=? toSiteRoot "index.html"
+ , "." @=? toSiteRoot "/index.html"
+ , "../.." @=? toSiteRoot "foo/bar/qux"
+ ]
+ ]
diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs
index 8787bbd..cb6113d 100644
--- a/tests/TestSuite.hs
+++ b/tests/TestSuite.hs
@@ -8,6 +8,7 @@ import qualified Hakyll.Core.Routes.Tests
import qualified Hakyll.Web.Page.Tests
import qualified Hakyll.Web.RelativizeUrls.Tests
import qualified Hakyll.Web.Template.Tests
+import qualified Hakyll.Web.Util.Url.Tests
main :: IO ()
main = defaultMain
@@ -23,4 +24,6 @@ main = defaultMain
Hakyll.Web.RelativizeUrls.Tests.tests
, testGroup "Hakyll.Web.Template.Tests"
Hakyll.Web.Template.Tests.tests
+ , testGroup "Hakyll.Web.Util.Url.Tests"
+ Hakyll.Web.Util.Url.Tests.tests
]