summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-07 17:31:49 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-07 17:31:49 +0100
commit35e6572f6c30ffa9db61bb9ab71478cfb8d6aed1 (patch)
treee93fad57ca6905aa18d61ce4615a77df1e1d8d5a /src/Text/Hakyll
parent21196184f9135a552cef398c1e25ec101fcd604d (diff)
downloadhakyll-35e6572f6c30ffa9db61bb9ab71478cfb8d6aed1.tar.gz
Added general renderAndConcat function.
Diffstat (limited to 'src/Text/Hakyll')
-rw-r--r--src/Text/Hakyll/Page.hs10
-rw-r--r--src/Text/Hakyll/Render.hs12
2 files changed, 16 insertions, 6 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index 7219f1a..dcb9c97 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -51,11 +51,11 @@ writerOptions = defaultWriterOptions
renderFunction :: String -> (String -> String)
renderFunction ".html" = id
renderFunction ext = writeHtmlString writerOptions .
- renderFunction' ext defaultParserState
- where renderFunction' ".markdown" = readMarkdown
- renderFunction' ".md" = readMarkdown
- renderFunction' ".tex" = readLaTeX
- renderFunction' _ = readMarkdown
+ readFunction ext defaultParserState
+ where readFunction ".markdown" = readMarkdown
+ readFunction ".md" = readMarkdown
+ readFunction ".tex" = readLaTeX
+ readFunction _ = readMarkdown
readMetaData :: Handle -> IO [(String, String)]
readMetaData handle = do
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index a69d27d..79f8764 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -1,6 +1,7 @@
module Text.Hakyll.Render
( renderPage,
renderAndWrite,
+ renderAndConcat,
static,
staticDirectory
) where
@@ -26,7 +27,7 @@ renderPage templatePath page = do
templateString <- liftM B.pack $ hGetContents handle
seq templateString $ hClose handle
let body = substitute templateString (createContext page)
- return $ addContext "body" (B.unpack body) page
+ return $ M.insert "body" body page
renderAndWrite :: FilePath -> Page -> IO ()
renderAndWrite templatePath page = do
@@ -35,6 +36,15 @@ renderAndWrite templatePath page = do
makeDirectories destination
B.writeFile destination (getBody rendered)
+renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
+renderAndConcat templatePath paths = foldM concatRender' B.empty paths
+ where concatRender' :: B.ByteString -> FilePath -> IO B.ByteString
+ concatRender' chunk path = do
+ page <- readPage path
+ rendered <- renderPage templatePath page
+ let body = getBody rendered
+ return $ B.append chunk $ body
+
static :: FilePath -> IO ()
static source = do
makeDirectories destination