From 8bb89a83b21dab7597e741140d4cf7530c47c4ee Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Sat, 6 Feb 2016 19:47:43 +0000 Subject: Add Snippet expression for snippet includes --- src/Hakyll/Web/Template/Context.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) -- cgit v1.2.3