summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-10 12:16:47 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-10 12:16:47 +0100
commitbc71d54ab732d71e2f1a3c5e3dce9f3231334605 (patch)
tree94c9f6875050f998118139ebe03709d4d1aa5af9 /src/Text/Hakyll
parent3753db702c6503ccbbe6eef7798243902c49a90c (diff)
downloadhakyll-bc71d54ab732d71e2f1a3c5e3dce9f3231334605.tar.gz
Started working on relative-url branch.
Diffstat (limited to 'src/Text/Hakyll')
-rw-r--r--src/Text/Hakyll/Context.hs7
-rw-r--r--src/Text/Hakyll/File.hs7
-rw-r--r--src/Text/Hakyll/Page.hs1
3 files changed, 15 insertions, 0 deletions
diff --git a/src/Text/Hakyll/Context.hs b/src/Text/Hakyll/Context.hs
index 22409bf..3d6f88c 100644
--- a/src/Text/Hakyll/Context.hs
+++ b/src/Text/Hakyll/Context.hs
@@ -3,6 +3,7 @@ module Text.Hakyll.Context
( ContextManipulation
, renderValue
, renderDate
+ , ignoreKeys
) where
import qualified Data.Map as M
@@ -44,3 +45,9 @@ renderDate key format defaultValue context =
"%Y-%m-%d"
dateString :: Maybe UTCTime
return $ formatTime defaultTimeLocale format time
+
+-- | Ignore a number of keys during the render phase.
+ignoreKeys :: [String] -> ContextManipulation
+ignoreKeys keyList = M.union (M.fromList pairs)
+ where pairs = map pair keyList
+ pair key = (B.pack $ '$' : key, B.pack $ '$' : key)
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs
index 400d156..c285433 100644
--- a/src/Text/Hakyll/File.hs
+++ b/src/Text/Hakyll/File.hs
@@ -4,6 +4,7 @@ module Text.Hakyll.File
( toDestination
, toCache
, toURL
+ , toRoot
, removeSpaces
, makeDirectories
, getRecursiveContents
@@ -35,6 +36,12 @@ toCache path = "_cache" </> (removeLeadingSeparator path)
toURL :: FilePath -> FilePath
toURL = flip addExtension ".html" . dropExtension
+-- | Get the relative url to the site root, for a given (absolute) url
+toRoot :: FilePath -> FilePath
+toRoot = joinPath . map parent . splitPath
+ . takeDirectory . removeLeadingSeparator
+ where parent = const ".."
+
-- | Swaps spaces for '-'.
removeSpaces :: FilePath -> FilePath
removeSpaces = map swap
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index 7baf31b..85fd062 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -121,6 +121,7 @@ readPage pagePath = do
[ (B.pack "body", rendered)
, packPair ("url", url)
, packPair ("path", pagePath)
+ , packPair ("root", toRoot url)
] ++ map packPair context
-- Cache if needed