diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-06-18 00:13:10 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-06-18 00:13:10 +0200 |
commit | 2282e78e9c9a6fd0919a13a11e070ac52cdce52f (patch) | |
tree | 271e4f519aa8efbe4f26c7299f6af65636cbb2b1 /src/Text/Hakyll | |
parent | 2a21970c93b40717da3dabbd242b3b6b242c310a (diff) | |
download | hakyll-2282e78e9c9a6fd0919a13a11e070ac52cdce52f.tar.gz |
Allow markdown/tex/... in templates
Diffstat (limited to 'src/Text/Hakyll')
-rw-r--r-- | src/Text/Hakyll/Internal/Page.hs | 5 | ||||
-rw-r--r-- | src/Text/Hakyll/Internal/Template.hs | 18 |
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 |