on master help sign in
Merge pull request #402 from Nicowcow/snippet-include
3ebdc76Jasper Van der Jeugt
src/Hakyll/Web/Template/Context.hs+17
@@ -18,6 +18,7 @@ module Hakyll.Web.Template.Context
18 , urlField
18 , urlField
19 , pathField
19 , pathField
20 , titleField
20 , titleField
21+ , snippetField
21 , dateField
22 , dateField
22 , dateFieldWith
23 , dateFieldWith
23 , getItemUTC
24 , getItemUTC
@@ -143,6 +144,22 @@ mapContext f (Context c) = Context $ \k a i -> do
143 "Hakyll.Web.Template.Context.mapContext: " ++
144 "Hakyll.Web.Template.Context.mapContext: " ++
144 "can't map over a ListField!"
145 "can't map over a ListField!"
145
146
147+--------------------------------------------------------------------------------
148+-- | A context that allows snippet inclusion. In processed file, use as:
149+--
150+-- > ...
151+-- > $snippet("path/to/snippet/")$
152+-- > ...
153+--
154+-- The contents of the included file will not be interpolated.
155+--
156+snippetField :: Context String
157+snippetField = functionField "snippet" f
158+ where
159+ f [contentsPath] _ = loadBody (fromFilePath contentsPath)
160+ f _ i = error $
161+ "Too many arguments to function 'snippet()' in item " ++
162+ show (itemIdentifier i)
146
163
147--------------------------------------------------------------------------------
164--------------------------------------------------------------------------------
148-- | A context that contains (in that order)
165-- | A context that contains (in that order)