on master help sign in
Made inner loops have access to outer loop values
8ae8f52iko
lib/Hakyll/Web/Template/Context.hs+2−2
@@ -272,8 +272,8 @@ titleField = mapContext takeBaseName . pathField
272--
272--
273-- As another alternative, if none of the above matches, and the file has a
273-- As another alternative, if none of the above matches, and the file has a
274-- path which contains nested directories specifying a date, then that date
274-- path which contains nested directories specifying a date, then that date
275−-- will be used. In other words, if the path is of the form
275+-- will be used. In other words, if the path is of the form
276−-- @**//yyyy//mm//dd//**//main.extension@ .
276+-- @**//yyyy//mm//dd//**//main.extension@ .
277-- As above, in case of multiple matches, the rightmost one is used.
277-- As above, in case of multiple matches, the rightmost one is used.
278
278
279dateField :: String -- ^ Key in which the rendered date should be placed
279dateField :: String -- ^ Key in which the rendered date should be placed
lib/Hakyll/Web/Template/Internal.hs+7−1
@@ -18,6 +18,7 @@ module Hakyll.Web.Template.Internal
18
18
19
19
20--------------------------------------------------------------------------------
20--------------------------------------------------------------------------------
21+import Control.Applicative ((<|>))
21import Control.Monad.Except (MonadError (..))
22import Control.Monad.Except (MonadError (..))
22import Data.Binary (Binary)
23import Data.Binary (Binary)
23import Data.List (intercalate)
24import Data.List (intercalate)
@@ -134,8 +135,13 @@ applyTemplate' tes context x = go tes
134 "got StringField for expr " ++ show e
135 "got StringField for expr " ++ show e
135 ListField c xs -> do
136 ListField c xs -> do
136 sep <- maybe (return "") go s
137 sep <- maybe (return "") go s
137− bs <- mapM (applyTemplate' b c) xs
138+ bs <- mapM (applyTemplate' b $ combineContexts context x c) xs
138 return $ intercalate sep bs
139 return $ intercalate sep bs
140+ where
141+ combineContexts :: Context a -> Item a -> Context b -> Context b
142+ combineContexts ca ia cb = Context $ \ k' args' ib' ->
143+ unContext cb k' args' ib'
144+ <|> unContext ca k' args' ia
139
145
140 applyElem (Partial e) = do
146 applyElem (Partial e) = do
141 p <- applyExpr e >>= getString e
147 p <- applyExpr e >>= getString e