@@ -86,19 +86,18 @@ metaToContext' :: (Monad m, TemplateTarget a)
8686metaToContext' blockWriter inlineWriter (Meta metamap) =
8787 Context <$> mapM (metaValueToVal blockWriter inlineWriter) metamap
8888
89−-- | Add variables to a template Context, replacing any existing values.
89+-- | Add variables to a template Context, using monoidal append.
90+-- Also add `meta-json`. Note that metadata values are used
91+-- in template contexts only when like-named variables aren't set.
9092addVariablesToContext :: TemplateTarget a
9193 => WriterOptions -> Context a -> Context a
92−addVariablesToContext opts (Context m1) =
93− Context (m1 `M.union` m2 `M.union` m3)
94+addVariablesToContext opts c1 =
95+ c2 <> (fromText <$> writerVariables opts) <> c1
9496 where
95− m2 = case traverse go (writerVariables opts) of
96− Just (Context x) -> x
97− Nothing -> mempty
98− m3 = M.insert "meta-json" (SimpleVal $ literal $ fromText jsonrep)
99− mempty
100− go = Just . fromText
101− jsonrep = UTF8.toText $ BL.toStrict $ encode $ toJSON m1
97+ c2 = Context $
98+ M.insert "meta-json" (SimpleVal $ literal $ fromText jsonrep)
99+ mempty
100+ jsonrep = UTF8.toText $ BL.toStrict $ encode $ toJSON c1
102101
103102metaValueToVal :: (Monad m, TemplateTarget a)
104103 => ([Block] -> m (Doc a))