diff options
Diffstat (limited to 'src/Hakyll/Web/Template')
-rw-r--r-- | src/Hakyll/Web/Template/Context.hs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs index 269347b..fd9add9 100644 --- a/src/Hakyll/Web/Template/Context.hs +++ b/src/Hakyll/Web/Template/Context.hs @@ -3,6 +3,7 @@ module Hakyll.Web.Template.Context ( Context (..) , mapContext , field + , constField , defaultContext , bodyField @@ -15,6 +16,7 @@ module Hakyll.Web.Template.Context , dateFieldWith , modificationTimeField , modificationTimeFieldWith + , missingField ) where @@ -64,6 +66,11 @@ field key value = Context $ \k i -> if k == key then value i else empty -------------------------------------------------------------------------------- +constField :: String -> String -> Context a +constField key = field key . const . return + + +-------------------------------------------------------------------------------- defaultContext :: Context String defaultContext = bodyField "body" `mappend` @@ -194,4 +201,6 @@ modificationTimeFieldWith locale key fmt = field key $ \i -> do -------------------------------------------------------------------------------- missingField :: Context a -missingField = Context $ \k _ -> return $ "$" ++ k ++ "$" +missingField = Context $ \k i -> compilerThrow $ + "Missing field $" ++ k ++ "$ in context for item " ++ + show (itemIdentifier i) |