on master help sign in
Make toSiteRoot work with /xxx URL's
cf71e29Jasper Van der Jeugt
src/Hakyll/Web/RelativizeUrls.hs+1−1
@@ -31,7 +31,7 @@ import Hakyll.Core.Compiler
31import Hakyll.Web.Page
31import Hakyll.Web.Page
32import Hakyll.Web.Util.Url
32import Hakyll.Web.Util.Url
33
33
34−-- | Compiler form of 'compressCss' which automatically picks the right root
34+-- | Compiler form of 'relativizeUrls' which automatically picks the right root
35-- path
35-- path
36--
36--
37relativizeUrlsCompiler :: Compiler (Page String) (Page String)
37relativizeUrlsCompiler :: Compiler (Page String) (Page String)
src/Hakyll/Web/Util/Url.hs+3−1
@@ -24,8 +24,10 @@ toUrl url = '/' : url
24-- | Get the relative url to the site root, for a given (absolute) url
24-- | Get the relative url to the site root, for a given (absolute) url
25--
25--
26toSiteRoot :: String -> String
26toSiteRoot :: String -> String
27−toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory
27+toSiteRoot = emptyException . joinPath . map parent
28+ . splitPath . takeDirectory . dropLeadingSlash
28 where
29 where
29 parent = const ".."
30 parent = const ".."
30 emptyException [] = "."
31 emptyException [] = "."
31 emptyException x = x
32 emptyException x = x
33+ dropLeadingSlash = dropWhile (== '/')
tests/Hakyll/Web/Util/Url/Tests.hsnew file+25
@@ -0,0 +1,25 @@
1+module Hakyll.Web.Util.Url.Tests
2+ ( tests
3+ ) where
4+
5+import Test.Framework
6+import Test.HUnit hiding (Test)
7+
8+import Hakyll.Web.Util.Url
9+import TestSuite.Util
10+
11+tests :: [Test]
12+tests = concat
13+ [ fromAssertions "toUrl"
14+ [ "/foo/bar.html" @=? toUrl "foo/bar.html"
15+ , "/" @=? toUrl "/"
16+ , "/funny-pics.html" @=? toUrl "/funny-pics.html"
17+ ]
18+
19+ , fromAssertions "toSiteRoot"
20+ [ ".." @=? toSiteRoot "/foo/bar.html"
21+ , "." @=? toSiteRoot "index.html"
22+ , "." @=? toSiteRoot "/index.html"
23+ , "../.." @=? toSiteRoot "foo/bar/qux"
24+ ]
25+ ]
tests/TestSuite.hs+3
@@ -8,6 +8,7 @@ import qualified Hakyll.Core.Routes.Tests
8import qualified Hakyll.Web.Page.Tests
8import qualified Hakyll.Web.Page.Tests
9import qualified Hakyll.Web.RelativizeUrls.Tests
9import qualified Hakyll.Web.RelativizeUrls.Tests
10import qualified Hakyll.Web.Template.Tests
10import qualified Hakyll.Web.Template.Tests
11+import qualified Hakyll.Web.Util.Url.Tests
11
12
12main :: IO ()
13main :: IO ()
13main = defaultMain
14main = defaultMain
@@ -23,4 +24,6 @@ main = defaultMain
23 Hakyll.Web.RelativizeUrls.Tests.tests
24 Hakyll.Web.RelativizeUrls.Tests.tests
24 , testGroup "Hakyll.Web.Template.Tests"
25 , testGroup "Hakyll.Web.Template.Tests"
25 Hakyll.Web.Template.Tests.tests
26 Hakyll.Web.Template.Tests.tests
27+ , testGroup "Hakyll.Web.Util.Url.Tests"
28+ Hakyll.Web.Util.Url.Tests.tests
26 ]
29 ]