diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-29 15:16:08 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-29 15:16:08 +0100 |
commit | 4f335aa6a2ffcd663c4bdb2c139bf4e1ea5237bf (patch) | |
tree | 2a20cb81317ca50d2666684ed50b5047b568f467 /examples/categoryblog/hakyll.hs | |
parent | 8ff702589fb5a1a2e600b204970084466de58a09 (diff) | |
download | hakyll-4f335aa6a2ffcd663c4bdb2c139bf4e1ea5237bf.tar.gz |
Added categoryblog example.
Diffstat (limited to 'examples/categoryblog/hakyll.hs')
-rw-r--r-- | examples/categoryblog/hakyll.hs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/examples/categoryblog/hakyll.hs b/examples/categoryblog/hakyll.hs new file mode 100644 index 0000000..2fef98e --- /dev/null +++ b/examples/categoryblog/hakyll.hs @@ -0,0 +1,64 @@ +module Main where + +import Text.Hakyll (hakyll) +import Text.Hakyll.Render +import Text.Hakyll.Tags (readCategoryMap) +import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces) +import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListingWith, createListing) +import Text.Hakyll.Context (ContextManipulation, renderDate) +import Text.Hakyll.Util (link) +import Data.List (sort) +import Data.Map (toList) +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 + + -- Read category map. + categoryMap <- readCategoryMap "categoryMap" renderablePosts + + -- Render all posts list. + renderPostList "posts.html" "All posts" renderablePosts + + -- Render post list per category + mapM_ (\(category, posts) -> renderPostList (categoryToURL category) ("Posts about " ++ category) posts) + (toList categoryMap) + + -- Render index, including recent posts. + let index = createListingWith postManipulation "index.html" + "templates/postitem.html" + (take 3 renderablePosts) + [ ("title", "Home") + , ("categories", categoryList categoryMap) + ] + renderChain ["index.html", "templates/default.html"] index + + -- Render all posts. + mapM_ (renderChainWith postManipulation + ["templates/post.html" + ,"templates/default.html" + ]) renderablePosts + + -- Render rss feed + let rss = createListing "rss.xml" "templates/rssitem.xml" (take 3 renderablePosts) [] + renderChain ["templates/rss.xml"] rss + + where postManipulation :: ContextManipulation + postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" + + categoryToURL category = "$root/categories/" ++ removeSpaces category ++ ".html" + + categoryList = uncurry categoryListItem <=< toList + + categoryListItem category posts = "<li>" ++ link category (categoryToURL category) + ++ " - " ++ show (length posts) ++ " items.</li>" + + renderPostList url title posts = do + let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)] + renderChain ["posts.html", "templates/default.html"] list |