summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template
diff options
context:
space:
mode:
authorTom Sydney Kerckhove <syd.kerckhove@student.kuleuven.be>2015-03-30 19:18:09 +0200
committerTom Sydney Kerckhove <syd.kerckhove@student.kuleuven.be>2015-03-30 19:18:09 +0200
commit8323f784b88d0c9a61e204da81412509b0baf0b9 (patch)
treeee466a584788ae7baf3fdeaf0f6e248ae8474da7 /src/Hakyll/Web/Template
parent46afe343fcb791d5ea1eee03c7b3f3f43c23ee07 (diff)
downloadhakyll-8323f784b88d0c9a61e204da81412509b0baf0b9.tar.gz
Added support for a custom teaser separator
This way you don't need to use the <!--more--> separator. You can define your own.
Diffstat (limited to 'src/Hakyll/Web/Template')
-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)