diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-18 22:41:41 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-11-18 22:41:41 +0100 |
commit | f6c4fb849d00dfc5b197651ac062e9c38d6375f5 (patch) | |
tree | 970da433f9fbb1203dcad9b805714f380ed171d5 /src/Hakyll | |
parent | 877cb21d1630d32c6e40eb7c6f0ecc7e1da2bd52 (diff) | |
download | hakyll-f6c4fb849d00dfc5b197651ac062e9c38d6375f5.tar.gz |
Add metadata to context
Diffstat (limited to 'src/Hakyll')
-rw-r--r-- | src/Hakyll/Web/Template/Context.hs | 9 |
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 |