summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-18 22:41:41 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-18 22:41:41 +0100
commitf6c4fb849d00dfc5b197651ac062e9c38d6375f5 (patch)
tree970da433f9fbb1203dcad9b805714f380ed171d5 /src/Hakyll
parent877cb21d1630d32c6e40eb7c6f0ecc7e1da2bd52 (diff)
downloadhakyll-f6c4fb849d00dfc5b197651ac062e9c38d6375f5.tar.gz
Add metadata to context
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Web/Template/Context.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index b3c2a6d..269347b 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -6,6 +6,7 @@ module Hakyll.Web.Template.Context
, defaultContext
, bodyField
+ , metadataField
, urlField
, pathField
, categoryField
@@ -66,6 +67,7 @@ field key value = Context $ \k i -> if k == key then value i else empty
defaultContext :: Context String
defaultContext =
bodyField "body" `mappend`
+ metadataField `mappend`
urlField "url" `mappend`
pathField "path" `mappend`
categoryField "category" `mappend`
@@ -79,6 +81,13 @@ bodyField key = field key $ return . itemBody
--------------------------------------------------------------------------------
+metadataField :: Context String
+metadataField = Context $ \k i -> do
+ metadata <- getMetadata $ itemIdentifier i
+ maybe empty return $ M.lookup k metadata
+
+
+--------------------------------------------------------------------------------
urlField :: String -> Context a
urlField key = field key $
fmap (maybe empty toUrl) . getRoute . itemIdentifier