on master help sign in
Added general renderAndConcat function.
commit35e6572f6c30ffa9db61bb9ab71478cfb8d6aed1 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateMon 7 Dec 2009, 17:31 (17 years ago) parent2119618
3 files changed+17−6
hakyll.cabal+1 src/Text/Hakyll/Page.hs+5−5 src/Text/Hakyll/Render.hs+11−1
hakyll.cabal+1
@@ -7,6 +7,7 @@ Description:
77 creating blogs.
88Author: Jasper Van der Jeugt
99Maintainer: jaspervdj@gmail.com
10+Homepage: http://github.com/jaspervdj/Hakyll
1011License: BSD3
1112License-File: LICENSE
1213Category: Text
src/Text/Hakyll/Page.hs+5−5
@@ -51,11 +51,11 @@ writerOptions = defaultWriterOptions
5151renderFunction :: String -> (String -> String)
5252renderFunction ".html" = id
5353renderFunction ext = writeHtmlString writerOptions .
54− renderFunction' ext defaultParserState
55− where renderFunction' ".markdown" = readMarkdown
56− renderFunction' ".md" = readMarkdown
57− renderFunction' ".tex" = readLaTeX
58− renderFunction' _ = readMarkdown
54+ readFunction ext defaultParserState
55+ where readFunction ".markdown" = readMarkdown
56+ readFunction ".md" = readMarkdown
57+ readFunction ".tex" = readLaTeX
58+ readFunction _ = readMarkdown
5959
6060readMetaData :: Handle -> IO [(String, String)]
6161readMetaData handle = do
src/Text/Hakyll/Render.hs+11−1
@@ -1,6 +1,7 @@
11module Text.Hakyll.Render
22 ( renderPage,
33 renderAndWrite,
4+ renderAndConcat,
45 static,
56 staticDirectory
67 ) where
@@ -26,7 +27,7 @@ renderPage templatePath page = do
2627 templateString <- liftM B.pack $ hGetContents handle
2728 seq templateString $ hClose handle
2829 let body = substitute templateString (createContext page)
29− return $ addContext "body" (B.unpack body) page
30+ return $ M.insert "body" body page
3031
3132renderAndWrite :: FilePath -> Page -> IO ()
3233renderAndWrite templatePath page = do
@@ -35,6 +36,15 @@ renderAndWrite templatePath page = do
3536 makeDirectories destination
3637 B.writeFile destination (getBody rendered)
3738
39+renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
40+renderAndConcat templatePath paths = foldM concatRender' B.empty paths
41+ where concatRender' :: B.ByteString -> FilePath -> IO B.ByteString
42+ concatRender' chunk path = do
43+ page <- readPage path
44+ rendered <- renderPage templatePath page
45+ let body = getBody rendered
46+ return $ B.append chunk $ body
47+
3848static :: FilePath -> IO ()
3949static source = do
4050 makeDirectories destination