hakyll/examples/simpleblog/hakyll.hs

36 lines
1.3 KiB
Haskell
Raw Normal View History

2009-12-29 18:09:11 +00:00
module Main where
import Text.Hakyll (hakyll)
2010-01-10 20:45:36 +00:00
import Text.Hakyll.Render
import Text.Hakyll.Context
2009-12-29 18:09:11 +00:00
import Text.Hakyll.File (getRecursiveContents, directory)
import Text.Hakyll.Renderables (createPagePath, createCustomPage)
import Data.List (sort)
import Control.Monad (mapM_, liftM)
import Data.Either (Either(..))
main = hakyll $ do
-- Static directory.
directory css "css"
-- Find all post paths.
postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
let renderablePosts = map createPagePath postPaths
-- Render index, including recent posts.
let recentPosts = renderAndConcat "templates/postitem.html" $ take 3 renderablePosts
renderChain ["index.html", "templates/default.html"] $
2009-12-30 19:40:23 +00:00
createCustomPage "index.html" ("templates/postitem.html" : take 3 postPaths)
2009-12-29 18:09:11 +00:00
[("title", Left "Home"), ("posts", Right recentPosts)]
-- Render all posts list.
let postItems = renderAndConcat "templates/postitem.html" $ renderablePosts
renderChain ["posts.html", "templates/default.html"] $
createCustomPage "posts.html" ("templates/postitem.html" : postPaths)
[("title", Left "All posts"), ("posts", Right postItems)]
-- Render all posts.
putStrLn "Generating posts..."
mapM_ (renderChain ["templates/post.html", "templates/default.html"]) renderablePosts