Append missingField before applying templates
This gives better errror messages in some cases
This commit is contained in:
parent
82a725bd8f
commit
4280b75ef6
2 changed files with 6 additions and 7 deletions
|
@ -48,7 +48,7 @@ import qualified Hakyll.Core.Store as Store
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- | Get the underlying identifier. Only use this if you know what you're doing.
|
-- | Get the underlying identifier.
|
||||||
getUnderlying :: Compiler Identifier
|
getUnderlying :: Compiler Identifier
|
||||||
getUnderlying = compilerUnderlying <$> compilerAsk
|
getUnderlying = compilerUnderlying <$> compilerAsk
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
-- | This module provides means for reading and applying 'Template's.
|
-- | This module provides means for reading and applying 'Template's.
|
||||||
--
|
--
|
||||||
-- Templates are tools to convert data (pages) into a string. They are
|
-- Templates are tools to convert items into a string. They are perfectly suited
|
||||||
-- perfectly suited for laying out your site.
|
-- for laying out your site.
|
||||||
--
|
--
|
||||||
-- Let's look at an example template:
|
-- Let's look at an example template:
|
||||||
--
|
--
|
||||||
|
@ -22,9 +22,6 @@
|
||||||
-- > </body>
|
-- > </body>
|
||||||
-- > </html>
|
-- > </html>
|
||||||
--
|
--
|
||||||
-- We can use this template to render a 'Page' which has a body and a @$title$@
|
|
||||||
-- metadata field.
|
|
||||||
--
|
|
||||||
-- As you can see, the format is very simple -- @$key$@ is used to render the
|
-- As you can see, the format is very simple -- @$key$@ is used to render the
|
||||||
-- @$key$@ field from the page, everything else is literally copied. If you want
|
-- @$key$@ field from the page, everything else is literally copied. If you want
|
||||||
-- to literally insert @\"$key$\"@ into your page (for example, when you're
|
-- to literally insert @\"$key$\"@ into your page (for example, when you're
|
||||||
|
@ -48,6 +45,7 @@ module Hakyll.Web.Template
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
import Control.Monad (forM, liftM)
|
import Control.Monad (forM, liftM)
|
||||||
|
import Data.Monoid (mappend)
|
||||||
import Prelude hiding (id)
|
import Prelude hiding (id)
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,7 +72,8 @@ applyTemplate :: Template -- ^ Template
|
||||||
-> Item a -- ^ Page
|
-> Item a -- ^ Page
|
||||||
-> Compiler (Item String) -- ^ Resulting item
|
-> Compiler (Item String) -- ^ Resulting item
|
||||||
applyTemplate tpl context item = do
|
applyTemplate tpl context item = do
|
||||||
let context' k x = unContext context k x
|
-- Appending missingField gives better error messages
|
||||||
|
let context' k x = unContext (context `mappend` missingField) k x
|
||||||
body <- applyTemplateWith context' tpl item
|
body <- applyTemplateWith context' tpl item
|
||||||
return $ itemSetBody body item
|
return $ itemSetBody body item
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue