@@ -128,7 +128,7 @@
129-- > $for(counts)-$
129-- > $for(counts)-$
130-- > $count$
130-- > $count$
131−-- > $-sep-$...
131+-- > $-sep$...
132-- > $-endfor$
132-- > $-endfor$
@@ -148,6 +148,7 @@ module Hakyll.Web.Template
148 , loadAndApplyTemplate
148 , loadAndApplyTemplate
149 , applyAsTemplate
149 , applyAsTemplate
150 , readTemplate
150 , readTemplate
151+ , unsafeReadTemplateFile
@@ -188,24 +189,31 @@ instance IsString Template where
188 fromString = readTemplate
189 fromString = readTemplate
192+--------------------------------------------------------------------------------
193+-- | Wrap the constructor to ensure trim is called.
194+template :: [TemplateElement] -> Template
195+template = Template . trim
191--------------------------------------------------------------------------------
198--------------------------------------------------------------------------------
192readTemplate :: String -> Template
199readTemplate :: String -> Template
193readTemplate = Template . trim . readTemplateElems
200readTemplate = Template . trim . readTemplateElems
196--------------------------------------------------------------------------------
202--------------------------------------------------------------------------------
197-- | Read a template, without metadata header
203-- | Read a template, without metadata header
198templateBodyCompiler :: Compiler (Item Template)
204templateBodyCompiler :: Compiler (Item Template)
199templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
205templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
200 item <- getResourceBody
206 item <- getResourceBody
201− return $ fmap readTemplate item
207+ file <- getResourceFilePath
208+ return $ fmap (template . readTemplateElemsFile file) item
203--------------------------------------------------------------------------------
210--------------------------------------------------------------------------------
204-- | Read complete file contents as a template
211-- | Read complete file contents as a template
205templateCompiler :: Compiler (Item Template)
212templateCompiler :: Compiler (Item Template)
206templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
213templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
207 item <- getResourceString
214 item <- getResourceString
208− return $ fmap readTemplate item
215+ file <- getResourceFilePath
216+ return $ fmap (template . readTemplateElemsFile file) item
211--------------------------------------------------------------------------------
219--------------------------------------------------------------------------------
@@ -317,5 +325,14 @@ applyAsTemplate :: Context String -- ^ Context
317 -> Item String -- ^ Item and template
325 -> Item String -- ^ Item and template
318 -> Compiler (Item String) -- ^ Resulting item
326 -> Compiler (Item String) -- ^ Resulting item
319applyAsTemplate context item =
327applyAsTemplate context item =
320− let tpl = readTemplate $ itemBody item
328+ let tpl = template $ readTemplateElemsFile file (itemBody item)
329+ file = toFilePath $ itemIdentifier item
321 in applyTemplate tpl context item
330 in applyTemplate tpl context item
333+--------------------------------------------------------------------------------
334+unsafeReadTemplateFile :: FilePath -> Compiler Template
335+unsafeReadTemplateFile file = do
336+ tpl <- unsafeCompiler $ readFile file
337+ pure $ template $ readTemplateElemsFile file tpl