@@ -7,18 +7,18 @@ module Text.Hakyll.Internal.Template
77 , finalSubstitute
88 ) where
99
10−import qualified Data.Map as M
1110import Data.List (isPrefixOf)
1211import Data.Char (isAlphaNum)
1312import Data.Binary
1413import Control.Monad (liftM, liftM2)
1514import Data.Maybe (fromMaybe)
1615import System.FilePath ((</>))
17−import Control.Monad.Reader (liftIO)
16+import qualified Data.Map as M
1817
1918import Text.Hakyll.Context (Context)
2019import Text.Hakyll.HakyllMonad (Hakyll)
2120import Text.Hakyll.Internal.Cache
21+import Text.Hakyll.Internal.Page
2222
2323-- | Datatype used for template substitutions.
2424data Template = Chunk String Template
@@ -44,11 +44,15 @@ fromString string
4444readTemplate :: FilePath -> Hakyll Template
4545readTemplate path = do
4646 isCacheMoreRecent' <- isCacheMoreRecent fileName [path]
47− if isCacheMoreRecent' then getFromCache fileName
48− else do content <- liftIO $ readFile path
49− let template = fromString content
50− storeInCache template fileName
51− return template
47+ if isCacheMoreRecent'
48+ then getFromCache fileName
49+ else do
50+ page <- readPage path
51+ let body = fromMaybe (error $ "No body in template " ++ fileName)
52+ (M.lookup "body" page)
53+ template = fromString body
54+ storeInCache template fileName
55+ return template
5256 where
5357 fileName = "templates" </> path
5458