on master help sign in
Started working on relative-url branch.
bc71d54Jasper Van der Jeugt
src/Text/Hakyll/Context.hs+7
@@ -3,6 +3,7 @@ module Text.Hakyll.Context
3 ( ContextManipulation
3 ( ContextManipulation
4 , renderValue
4 , renderValue
5 , renderDate
5 , renderDate
6+ , ignoreKeys
6 ) where
7 ) where
7
8
8import qualified Data.Map as M
9import qualified Data.Map as M
@@ -44,3 +45,9 @@ renderDate key format defaultValue context =
44 "%Y-%m-%d"
45 "%Y-%m-%d"
45 dateString :: Maybe UTCTime
46 dateString :: Maybe UTCTime
46 return $ formatTime defaultTimeLocale format time
47 return $ formatTime defaultTimeLocale format time
48+
49+-- | Ignore a number of keys during the render phase.
50+ignoreKeys :: [String] -> ContextManipulation
51+ignoreKeys keyList = M.union (M.fromList pairs)
52+ where pairs = map pair keyList
53+ pair key = (B.pack $ '$' : key, B.pack $ '$' : key)
src/Text/Hakyll/File.hs+7
@@ -4,6 +4,7 @@ module Text.Hakyll.File
4 ( toDestination
4 ( toDestination
5 , toCache
5 , toCache
6 , toURL
6 , toURL
7+ , toRoot
7 , removeSpaces
8 , removeSpaces
8 , makeDirectories
9 , makeDirectories
9 , getRecursiveContents
10 , getRecursiveContents
@@ -35,6 +36,12 @@ toCache path = "_cache" </> (removeLeadingSeparator path)
35toURL :: FilePath -> FilePath
36toURL :: FilePath -> FilePath
36toURL = flip addExtension ".html" . dropExtension
37toURL = flip addExtension ".html" . dropExtension
37
38
39+-- | Get the relative url to the site root, for a given (absolute) url
40+toRoot :: FilePath -> FilePath
41+toRoot = joinPath . map parent . splitPath
42+ . takeDirectory . removeLeadingSeparator
43+ where parent = const ".."
44+
38-- | Swaps spaces for '-'.
45-- | Swaps spaces for '-'.
39removeSpaces :: FilePath -> FilePath
46removeSpaces :: FilePath -> FilePath
40removeSpaces = map swap
47removeSpaces = map swap
src/Text/Hakyll/Page.hs+1
@@ -121,6 +121,7 @@ readPage pagePath = do
121 [ (B.pack "body", rendered)
121 [ (B.pack "body", rendered)
122 , packPair ("url", url)
122 , packPair ("url", url)
123 , packPair ("path", pagePath)
123 , packPair ("path", pagePath)
124+ , packPair ("root", toRoot url)
124 ] ++ map packPair context
125 ] ++ map packPair context
125
126
126 -- Cache if needed
127 -- Cache if needed
tests/Tests.hs+8−1
@@ -40,7 +40,10 @@ tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length
40 , testCase "renderDate 2" test_render_date1
40 , testCase "renderDate 2" test_render_date1
41 ]
41 ]
42
42
43+ , testGroup "File group" [ testCase "toRoot 1" test_to_root1
44+ , testCase "toRoot 2" test_to_root2
45+ , testCase "toRoot 3" test_to_root3
43− , testGroup "File group" [ testProperty "havingExtension count" prop_having_extension_count
46+ , testProperty "havingExtension count" prop_having_extension_count
44 , testCase "havingExtension 1" test_having_extension1
47 , testCase "havingExtension 1" test_having_extension1
45 , testCase "havingExtension 2" test_having_extension2
48 , testCase "havingExtension 2" test_having_extension2
46 ]
49 ]
@@ -93,6 +96,10 @@ test_render_date2 = M.lookup (B.pack "date") rendered @?= Just (B.pack "Unknown
93 "Unknown date"
96 "Unknown date"
94 (M.singleton (B.pack "path")
97 (M.singleton (B.pack "path")
95 (B.pack "2009-badness-30-a-title.markdown"))
98 (B.pack "2009-badness-30-a-title.markdown"))
99+-- toRoot test cases
100+test_to_root1 = toRoot "/posts/foo.html" @?= ".."
101+test_to_root2 = toRoot "posts/foo.html" @?= ".."
102+test_to_root3 = toRoot "foo.html" @?= ""
96
103
97-- Add an extension, and test that they have that extension
104-- Add an extension, and test that they have that extension
98prop_having_extension_count names extension =
105prop_having_extension_count names extension =