on master help sign in
Add constRoute
a27e254Jasper Van der Jeugt
src/Hakyll/Core/Routes.hs+6
@@ -33,6 +33,7 @@ module Hakyll.Core.Routes
33 , setExtension
33 , setExtension
34 , matchRoute
34 , matchRoute
35 , customRoute
35 , customRoute
36+ , constRoute
36 , gsubRoute
37 , gsubRoute
37 , composeRoutes
38 , composeRoutes
38 ) where
39 ) where
@@ -99,6 +100,11 @@ matchRoute pattern (Routes route) = Routes $ \id' ->
99customRoute :: (Identifier a -> FilePath) -> Routes
100customRoute :: (Identifier a -> FilePath) -> Routes
100customRoute f = Routes $ Just . f . castIdentifier
101customRoute f = Routes $ Just . f . castIdentifier
101
102
103+-- | A route that always gives the same result. Obviously, you should only use
104+-- this for a single compilation rule.
105+constRoute :: FilePath -> Routes
106+constRoute = customRoute . const
107+
102-- | Create a gsub route
108-- | Create a gsub route
103--
109--
104-- Example:
110-- Example:
tests/Hakyll/Core/Routes/Tests.hs+6
@@ -6,6 +6,7 @@ module Hakyll.Core.Routes.Tests
6import Test.Framework
6import Test.Framework
7import Test.HUnit hiding (Test)
7import Test.HUnit hiding (Test)
8
8
9+import Hakyll.Core.Identifier
9import Hakyll.Core.Routes
10import Hakyll.Core.Routes
10import TestSuite.Util
11import TestSuite.Util
11
12
@@ -16,6 +17,11 @@ tests = fromAssertions "runRoutes"
16 , Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
17 , Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
17 , Just "foo.html" @=? runRoutes (setExtension ".html") "foo.markdown"
18 , Just "foo.html" @=? runRoutes (setExtension ".html") "foo.markdown"
18
19
20+ , Just "neve ro ddo reven" @=?
21+ runRoutes (customRoute (reverse . toFilePath )) "never odd or even"
22+
23+ , Just "foo" @=? runRoutes (constRoute "foo") "bar"
24+
19 , Just "tags/bar.xml" @=?
25 , Just "tags/bar.xml" @=?
20 runRoutes (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
26 runRoutes (gsubRoute "rss/" (const "")) "tags/rss/bar.xml"
21 , Just "tags/bar.xml" @=?
27 , Just "tags/bar.xml" @=?