summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2016-04-07 08:47:09 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2016-04-07 08:47:09 +0100
commit3ebdc76a5518371d4e7bddf51554f8b2e49e5f35 (patch)
treebd1ab2fbb0c9de68fb6ad680ffe995196dd315d0 /src
parentafbc784dc0733bc5d0ff243e2ae9b9e5a8613f69 (diff)
parent8bb89a83b21dab7597e741140d4cf7530c47c4ee (diff)
downloadhakyll-3ebdc76a5518371d4e7bddf51554f8b2e49e5f35.tar.gz
Merge pull request #402 from Nicowcow/snippet-include
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 efe808a..b6c7994 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
@@ -143,6 +144,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)