@@ -6,6 +6,7 @@ module Hakyll.Web.Template.Context
66 , field
77 , constField
88 , listField
9+ , functionField
910 , mapContext
1011
1112 , defaultContext
@@ -86,6 +87,15 @@ listField :: String -> Context a -> Compiler [Item a] -> Context b
8687listField key c xs = field' key $ \_ -> fmap (ListField c) xs
8788
8889
90+--------------------------------------------------------------------------------
91+functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a
92+functionField name value = Context $ \k i -> case words k of
93+ [] -> empty
94+ (n : args)
95+ | n == name -> StringField <$> value args i
96+ | otherwise -> empty
97+
98+
8999--------------------------------------------------------------------------------
90100mapContext :: (String -> String) -> Context a -> Context a
91101mapContext f (Context c) = Context $ \k i -> do