on master help sign in
Made inner loops have access to outer loop values
commit8ae8f525ce09bc220c8b8c3b624f3663c87cf943 authoriko <ilyakooo0@gmail.com> dateSun 25 Aug 2019, 13:52 (7 years ago) parente8ea8cd
2 files changed+9−3
lib/Hakyll/Web/Template/Context.hs+2−2 lib/Hakyll/Web/Template/Internal.hs+7−1
lib/Hakyll/Web/Template/Context.hs+2−2
@@ -272,8 +272,8 @@ titleField = mapContext takeBaseName . pathField
272272--
273273-- As another alternative, if none of the above matches, and the file has a
274274-- 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
276−-- @**//yyyy//mm//dd//**//main.extension@ .
275+-- will be used. In other words, if the path is of the form
276+-- @**//yyyy//mm//dd//**//main.extension@ .
277277-- As above, in case of multiple matches, the rightmost one is used.
278278
279279dateField :: 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
1818
1919
2020--------------------------------------------------------------------------------
21+import Control.Applicative ((<|>))
2122import Control.Monad.Except (MonadError (..))
2223import Data.Binary (Binary)
2324import Data.List (intercalate)
@@ -134,8 +135,13 @@ applyTemplate' tes context x = go tes
134135 "got StringField for expr " ++ show e
135136 ListField c xs -> do
136137 sep <- maybe (return "") go s
137− bs <- mapM (applyTemplate' b c) xs
138+ bs <- mapM (applyTemplate' b $ combineContexts context x c) xs
138139 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
139145
140146 applyElem (Partial e) = do
141147 p <- applyExpr e >>= getString e