on master help sign in
teaserContext -> teaserField
commite687662ba0421729c4ab07c08744004c2ea1dd55 authorJasper Van der Jeugt <m@jaspervdj.be> dateThu 6 Jun 2013, 10:21 (13 years ago) parentfd91721
3 files changed+16−15
src/Hakyll/Core/Configuration.hs−1 src/Hakyll/Web/Template/Context.hs+13−11 web/tutorials/using-teasers-in-hakyll.markdown+3−3
src/Hakyll/Core/Configuration.hs−1
@@ -8,7 +8,6 @@ module Hakyll.Core.Configuration
88
99
1010--------------------------------------------------------------------------------
11−import Control.Monad (void)
1211import Data.Default (Default (..))
1312import Data.List (isPrefixOf, isSuffixOf)
1413import System.Directory (canonicalizePath)
src/Hakyll/Web/Template/Context.hs+13−11
@@ -8,7 +8,6 @@ module Hakyll.Web.Template.Context
88 , listField
99
1010 , defaultContext
11− , teaserContext
1211 , bodyField
1312 , metadataField
1413 , urlField
@@ -19,6 +18,7 @@ module Hakyll.Web.Template.Context
1918 , getItemUTC
2019 , modificationTimeField
2120 , modificationTimeFieldWith
21+ , teaserField
2222 , missingField
2323 ) where
2424
@@ -96,16 +96,6 @@ defaultContext =
9696 missingField
9797
9898
99−--------------------------------------------------------------------------------
100−-- | A context with "teaser" key which contain a teaser of the item.
101−-- The item is loaded from the given snapshot (which should be saved
102−-- in the user code before any templates are applied).
103−teaserContext :: Snapshot -> Context String
104−teaserContext snapshot = field "teaser" $ \item ->
105− (needlePrefix teaserSeparator . itemBody) <$>
106− loadSnapshot (itemIdentifier item) snapshot
107−
108−
10999--------------------------------------------------------------------------------
110100teaserSeparator :: String
111101teaserSeparator = "<!--more-->"
@@ -245,6 +235,18 @@ modificationTimeFieldWith locale key fmt = field key $ \i -> do
245235 return $ formatTime locale fmt mtime
246236
247237
238+--------------------------------------------------------------------------------
239+-- | A context with "teaser" key which contain a teaser of the item.
240+-- The item is loaded from the given snapshot (which should be saved
241+-- in the user code before any templates are applied).
242+teaserField :: String -- ^ Key to use
243+ -> Snapshot -- ^ Snapshot to load
244+ -> Context String -- ^ Resulting context
245+teaserField key snapshot = field key $ \item ->
246+ (needlePrefix teaserSeparator . itemBody) <$>
247+ loadSnapshot (itemIdentifier item) snapshot
248+
249+
248250--------------------------------------------------------------------------------
249251missingField :: Context a
250252missingField = Context $ \k i -> fail $
web/tutorials/using-teasers-in-hakyll.markdown+3−3
@@ -69,13 +69,13 @@ match "posts/*" $ do
6969You can read more about snapshots in
7070[Snapshots tutorial](/tutorials/05-snapshots-feeds.html).
7171
72−Then we use this snapshot while generating teasers using
73−`teaserContext` function:
72+Then we use this snapshot while generating teasers using the
73+`teaserField` function:
7474
7575``` haskell
7676 loadAndApplyTemplate
7777 "template/postitem.html"
78− (teaserContext "content" <> defaultContext)
78+ (teaserField "teaser" "content" <> defaultContext)
7979 item
8080```
8181