summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Web/Template')
-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