on master help sign in
Started working on relative-url branch.
commitbc71d54ab732d71e2f1a3c5e3dce9f3231334605 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 10 Jan 2010, 12:16 (17 years ago) parent3753db7
4 files changed+23−1
src/Text/Hakyll/Context.hs+7 src/Text/Hakyll/File.hs+7 src/Text/Hakyll/Page.hs+1 tests/Tests.hs+8−1
src/Text/Hakyll/Context.hs+7
@@ -3,6 +3,7 @@ module Text.Hakyll.Context
33 ( ContextManipulation
44 , renderValue
55 , renderDate
6+ , ignoreKeys
67 ) where
78
89import qualified Data.Map as M
@@ -44,3 +45,9 @@ renderDate key format defaultValue context =
4445 "%Y-%m-%d"
4546 dateString :: Maybe UTCTime
4647 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
44 ( toDestination
55 , toCache
66 , toURL
7+ , toRoot
78 , removeSpaces
89 , makeDirectories
910 , getRecursiveContents
@@ -35,6 +36,12 @@ toCache path = "_cache" </> (removeLeadingSeparator path)
3536toURL :: FilePath -> FilePath
3637toURL = flip addExtension ".html" . dropExtension
3738
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+
3845-- | Swaps spaces for '-'.
3946removeSpaces :: FilePath -> FilePath
4047removeSpaces = map swap
src/Text/Hakyll/Page.hs+1
@@ -121,6 +121,7 @@ readPage pagePath = do
121121 [ (B.pack "body", rendered)
122122 , packPair ("url", url)
123123 , packPair ("path", pagePath)
124+ , packPair ("root", toRoot url)
124125 ] ++ map packPair context
125126
126127 -- Cache if needed
tests/Tests.hs+8−1
@@ -40,7 +40,10 @@ tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length
4040 , testCase "renderDate 2" test_render_date1
4141 ]
4242
43− , testGroup "File group" [ testProperty "havingExtension count" prop_having_extension_count
43+ , testGroup "File group" [ testCase "toRoot 1" test_to_root1
44+ , testCase "toRoot 2" test_to_root2
45+ , testCase "toRoot 3" test_to_root3
46+ , testProperty "havingExtension count" prop_having_extension_count
4447 , testCase "havingExtension 1" test_having_extension1
4548 , testCase "havingExtension 2" test_having_extension2
4649 ]
@@ -93,6 +96,10 @@ test_render_date2 = M.lookup (B.pack "date") rendered @?= Just (B.pack "Unknown
9396 "Unknown date"
9497 (M.singleton (B.pack "path")
9598 (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" @?= ""
96103
97104-- Add an extension, and test that they have that extension
98105prop_having_extension_count names extension =