summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Hakyll/Internal/Page.hs5
-rw-r--r--src/Text/Hakyll/Internal/Template.hs18
2 files changed, 14 insertions, 9 deletions
diff --git a/src/Text/Hakyll/Internal/Page.hs b/src/Text/Hakyll/Internal/Page.hs
index 115bc09..e2998a5 100644
--- a/src/Text/Hakyll/Internal/Page.hs
+++ b/src/Text/Hakyll/Internal/Page.hs
@@ -22,8 +22,9 @@ import Text.Hakyll.Internal.FileType
-- | Get a render function for a given extension.
getRenderFunction :: FileType -> Hakyll (String -> String)
-getRenderFunction Html = return id
-getRenderFunction Text = return id
+getRenderFunction Html = return id
+getRenderFunction Text = return id
+getRenderFunction UnknownFileType = return id
getRenderFunction fileType = do
parserState <- askHakyll pandocParserState
writerOptions <- askHakyll pandocWriterOptions
diff --git a/src/Text/Hakyll/Internal/Template.hs b/src/Text/Hakyll/Internal/Template.hs
index 8b4d6c7..b7d1db0 100644
--- a/src/Text/Hakyll/Internal/Template.hs
+++ b/src/Text/Hakyll/Internal/Template.hs
@@ -7,18 +7,18 @@ module Text.Hakyll.Internal.Template
, finalSubstitute
) where
-import qualified Data.Map as M
import Data.List (isPrefixOf)
import Data.Char (isAlphaNum)
import Data.Binary
import Control.Monad (liftM, liftM2)
import Data.Maybe (fromMaybe)
import System.FilePath ((</>))
-import Control.Monad.Reader (liftIO)
+import qualified Data.Map as M
import Text.Hakyll.Context (Context)
import Text.Hakyll.HakyllMonad (Hakyll)
import Text.Hakyll.Internal.Cache
+import Text.Hakyll.Internal.Page
-- | Datatype used for template substitutions.
data Template = Chunk String Template
@@ -44,11 +44,15 @@ fromString string
readTemplate :: FilePath -> Hakyll Template
readTemplate path = do
isCacheMoreRecent' <- isCacheMoreRecent fileName [path]
- if isCacheMoreRecent' then getFromCache fileName
- else do content <- liftIO $ readFile path
- let template = fromString content
- storeInCache template fileName
- return template
+ if isCacheMoreRecent'
+ then getFromCache fileName
+ else do
+ page <- readPage path
+ let body = fromMaybe (error $ "No body in template " ++ fileName)
+ (M.lookup "body" page)
+ template = fromString body
+ storeInCache template fileName
+ return template
where
fileName = "templates" </> path