summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas Mattia <nicow.mattia@gmail.com>2016-02-06 19:47:43 +0000
committerNicolas Mattia <nicow.mattia@gmail.com>2016-04-06 21:32:15 +0100
commit8bb89a83b21dab7597e741140d4cf7530c47c4ee (patch)
tree44e759ab5e5d195f8e9638f989bdbae4b26561ea /src
parent6eb19c9eaacb6c9d0b1f9c3717bcaebbbf7cea19 (diff)
downloadhakyll-8bb89a83b21dab7597e741140d4cf7530c47c4ee.tar.gz
Add Snippet expression for snippet includes
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/Template/Context.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index 6879187..28e2ec5 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -18,6 +18,7 @@ module Hakyll.Web.Template.Context
, urlField
, pathField
, titleField
+ , snippetField
, dateField
, dateFieldWith
, getItemUTC
@@ -147,6 +148,22 @@ mapContext f (Context c) = Context $ \k a i -> do
"Hakyll.Web.Template.Context.mapContext: " ++
"can't map over a ListField!"
+--------------------------------------------------------------------------------
+-- | A context that allows snippet inclusion. In processed file, use as:
+--
+-- > ...
+-- > $snippet("path/to/snippet/")$
+-- > ...
+--
+-- The contents of the included file will not be interpolated.
+--
+snippetField :: Context String
+snippetField = functionField "snippet" f
+ where
+ f [contentsPath] _ = loadBody (fromFilePath contentsPath)
+ f _ i = error $
+ "Too many arguments to function 'snippet()' in item " ++
+ show (itemIdentifier i)
--------------------------------------------------------------------------------
-- | A context that contains (in that order)