summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-11 20:41:49 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-11 20:41:49 +0100
commitd988921714f3335b9755e30ea893e3e2b47d72b6 (patch)
tree873bbc9dc1f2b836c8f0b8973ce3fe34a9892b40 /src
parentd83791c106bf898e4397b592133642fbed5b8568 (diff)
downloadhakyll-d988921714f3335b9755e30ea893e3e2b47d72b6.tar.gz
Added CustomPage.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Hakyll/CustomPage.hs29
-rw-r--r--src/Text/Hakyll/Render.hs11
2 files changed, 34 insertions, 6 deletions
diff --git a/src/Text/Hakyll/CustomPage.hs b/src/Text/Hakyll/CustomPage.hs
new file mode 100644
index 0000000..c18bb2d
--- /dev/null
+++ b/src/Text/Hakyll/CustomPage.hs
@@ -0,0 +1,29 @@
+module Text.Hakyll.CustomPage
+ ( CustomPage,
+ createCustomPage
+ ) where
+
+import System.FilePath
+import qualified Data.ByteString.Lazy.Char8 as B
+import qualified Data.Map as M
+import Control.Monad
+import Text.Hakyll.Renderable
+
+data CustomPage = CustomPage { url :: String,
+ dependencies :: [FilePath],
+ mapping :: [(String, Either String (IO B.ByteString))]
+ }
+
+createCustomPage :: String
+ -> [FilePath]
+ -> [(String, Either String (IO B.ByteString))]
+ -> CustomPage
+createCustomPage = CustomPage
+
+instance Renderable CustomPage where
+ getDependencies = dependencies
+ getURL = url
+ toContext page = do
+ values <- mapM (either (return . B.pack) (>>= return) . snd) (mapping page)
+ let keys = map (B.pack . fst) (mapping page)
+ return $ M.fromList $ (B.pack "url", B.pack $ url page) : zip keys values
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index 8449180..ed888ed 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -40,12 +40,11 @@ writePage page = do
makeDirectories destination
B.writeFile destination (getBody page)
-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 <- render templatePath page
+renderAndConcat :: Renderable a => FilePath -> [a] -> IO B.ByteString
+renderAndConcat templatePath renderables = foldM concatRender' B.empty renderables
+ where concatRender' :: Renderable a => B.ByteString -> a -> IO B.ByteString
+ concatRender' chunk renderable = do
+ rendered <- render templatePath renderable
let body = getBody rendered
return $ B.append chunk $ body