summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/Feed.hs6
-rw-r--r--src/Hakyll/Web/Template.hs9
-rw-r--r--src/Hakyll/Web/Template/Internal.hs9
3 files changed, 19 insertions, 5 deletions
diff --git a/src/Hakyll/Web/Feed.hs b/src/Hakyll/Web/Feed.hs
index 8598f8a..16b6dc0 100644
--- a/src/Hakyll/Web/Feed.hs
+++ b/src/Hakyll/Web/Feed.hs
@@ -33,6 +33,7 @@ import Hakyll.Core.Compiler.Internal
import Hakyll.Core.Item
import Hakyll.Web.Template
import Hakyll.Web.Template.Context
+import Hakyll.Web.Template.Internal
import Hakyll.Web.Template.List
@@ -72,7 +73,10 @@ renderFeed feedPath itemPath config itemContext items = do
applyTemplate feedTpl feedContext body
where
-- Auxiliary: load a template from a datafile
- loadTemplate = fmap readTemplate . readFile <=< getDataFileName
+ loadTemplate path = do
+ file <- getDataFileName path
+ templ <- readFile file
+ return $ readTemplateFile file templ
itemContext' = mconcat
[ itemContext
diff --git a/src/Hakyll/Web/Template.hs b/src/Hakyll/Web/Template.hs
index 65c4ac9..a662906 100644
--- a/src/Hakyll/Web/Template.hs
+++ b/src/Hakyll/Web/Template.hs
@@ -147,14 +147,16 @@ import Hakyll.Web.Template.Internal
templateBodyCompiler :: Compiler (Item Template)
templateBodyCompiler = cached "Hakyll.Web.Template.templateBodyCompiler" $ do
item <- getResourceBody
- return $ fmap readTemplate item
+ file <- getResourceFilePath
+ return $ fmap (readTemplateFile file) item
--------------------------------------------------------------------------------
-- | Read complete file contents as a template
templateCompiler :: Compiler (Item Template)
templateCompiler = cached "Hakyll.Web.Template.templateCompiler" $ do
item <- getResourceString
- return $ fmap readTemplate item
+ file <- getResourceFilePath
+ return $ fmap (readTemplateFile file) item
--------------------------------------------------------------------------------
@@ -259,5 +261,6 @@ applyAsTemplate :: Context String -- ^ Context
-> Item String -- ^ Item and template
-> Compiler (Item String) -- ^ Resulting item
applyAsTemplate context item =
- let tpl = readTemplate $ itemBody item
+ let tpl = readTemplateFile file (itemBody item)
+ file = toFilePath $ itemIdentifier item
in applyTemplate tpl context item
diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs
index aa8e080..a63c40d 100644
--- a/src/Hakyll/Web/Template/Internal.hs
+++ b/src/Hakyll/Web/Template/Internal.hs
@@ -8,6 +8,7 @@ module Hakyll.Web.Template.Internal
, TemplateExpr (..)
, TemplateElement (..)
, readTemplate
+ , readTemplateFile
) where
@@ -120,10 +121,16 @@ instance Binary TemplateExpr where
--------------------------------------------------------------------------------
readTemplate :: String -> Template
-readTemplate input = case P.parse topLevelTemplate "" input of
+readTemplate = readTemplateFile "{literal}"
+
+
+--------------------------------------------------------------------------------
+readTemplateFile :: FilePath -> String -> Template
+readTemplateFile file input = case P.parse topLevelTemplate file input of
Left err -> error $ "Cannot parse template: " ++ show err
Right t -> t
+
--------------------------------------------------------------------------------
topLevelTemplate :: P.Parser Template
topLevelTemplate = Template <$>