summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2015-04-03 16:48:36 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2015-04-03 16:48:36 +0200
commit9fa80ad38cdec6a1c3694562b0c378a782e50617 (patch)
tree22cac80ed0684d718b8aaa56ea76625daf915747
parentdf9dba3ef48eb2fc2ef6096fef85a5fd02364e5c (diff)
parent8323f784b88d0c9a61e204da81412509b0baf0b9 (diff)
downloadhakyll-9fa80ad38cdec6a1c3694562b0c378a782e50617.tar.gz
Merge pull request #342 from NorfairKing/general-teaser-seperator
Added support for a custom teaser separator
-rw-r--r--src/Hakyll/Web/Template/Context.hs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index f5646b9..f74af25 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -23,6 +23,7 @@ module Hakyll.Web.Template.Context
, modificationTimeField
, modificationTimeFieldWith
, teaserField
+ , teaserFieldWithSeperator
, missingField
) where
@@ -318,9 +319,18 @@ modificationTimeFieldWith locale key fmt = field key $ \i -> do
teaserField :: String -- ^ Key to use
-> Snapshot -- ^ Snapshot to load
-> Context String -- ^ Resulting context
-teaserField key snapshot = field key $ \item -> do
+teaserField = teaserFieldWithSeperator teaserSeparator
+
+-- | A context with "teaser" key which contain a teaser of the item, defined as the snapshot content before the teaser separator.
+-- The item is loaded from the given snapshot (which should be saved
+-- in the user code before any templates are applied).
+teaserFieldWithSeperator :: String -- ^ Separator to use
+ -> String -- ^ Key to use
+ -> Snapshot -- ^ Snapshot to load
+ -> Context String -- ^ Resulting context
+teaserFieldWithSeperator separator key snapshot = field key $ \item -> do
body <- itemBody <$> loadSnapshot (itemIdentifier item) snapshot
- case needlePrefix teaserSeparator body of
+ case needlePrefix separator body of
Nothing -> fail $
"Hakyll.Web.Template.Context: no teaser defined for " ++
show (itemIdentifier item)