on master help sign in
Merge pull request #402 from Nicowcow/snippet-include

Add Snippet expression for snippet includes

commit3ebdc76a5518371d4e7bddf51554f8b2e49e5f35 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 7 Apr 2016, 08:47 (11 years ago) parentafbc7848bb89a8
1 file changed+17
src/Hakyll/Web/Template/Context.hs+17
src/Hakyll/Web/Template/Context.hs+17
@@ -18,6 +18,7 @@ module Hakyll.Web.Template.Context
1818 , urlField
1919 , pathField
2020 , titleField
21+ , snippetField
2122 , dateField
2223 , dateFieldWith
2324 , getItemUTC
@@ -143,6 +144,22 @@ mapContext f (Context c) = Context $ \k a i -> do
143144 "Hakyll.Web.Template.Context.mapContext: " ++
144145 "can't map over a ListField!"
145146
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)
146163
147164--------------------------------------------------------------------------------
148165-- | A context that contains (in that order)