From 4e6ab05b7803833d07e502797ad28c908f7d14d2 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 21 Mar 2010 15:57:12 +0100 Subject: Updated tagblog example to hakyll-2.x --- examples/tagblog/hakyll.hs | 57 ++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'examples/tagblog/hakyll.hs') diff --git a/examples/tagblog/hakyll.hs b/examples/tagblog/hakyll.hs index c2f16cf..515d0d2 100644 --- a/examples/tagblog/hakyll.hs +++ b/examples/tagblog/hakyll.hs @@ -1,60 +1,67 @@ module Main where +import Control.Arrow ((>>>)) import Text.Hakyll (hakyll) import Text.Hakyll.Render -import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks) +import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks, withTagMap) +import Text.Hakyll.Feed (FeedConfiguration (..), renderRss) import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces) -import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListingWith, createListing) -import Text.Hakyll.Context (ContextManipulation, renderDate) +import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing) +import Text.Hakyll.ContextManipulations (renderDate, copyValue) import Data.List (sort) import Data.Map (toList) import Control.Monad (mapM_, liftM) import Data.Either (Either(..)) -main = hakyll $ do +main = hakyll "http://example.com" $ do -- Static directory. directory css "css" -- Find all post paths. postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts" - let renderablePosts = map createPagePath postPaths + let renderablePosts = map ((>>> postManipulation) . createPage) postPaths -- Read tag map. - tagMap <- readTagMap "postTags" renderablePosts + let tagMap = readTagMap "postTags" postPaths -- Render all posts list. renderPostList "posts.html" "All posts" renderablePosts -- Render post list per tag - mapM_ (\(tag, posts) -> renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) posts) - (toList tagMap) + withTagMap tagMap $ \tag posts -> + renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) (map (>>> postManipulation) posts) -- Render index, including recent posts. - let tagCloud = renderTagCloud tagMap tagToUrl 100 200 - index = createListingWith postManipulation "index.html" - "templates/postitem.html" - (take 3 renderablePosts) - [ ("title", "Home") - , ("tagcloud", tagCloud) - ] + let tagCloud = tagMap >>> renderTagCloud tagToUrl 100 200 + index = createListing "index.html" + ["templates/postitem.html"] + (take 3 renderablePosts) + [ ("title", Left "Home") + , ("tagcloud", Right tagCloud) + ] renderChain ["index.html", "templates/default.html"] index -- Render all posts. - mapM_ (renderChainWith postManipulation - ["templates/post.html" - ,"templates/default.html" - ]) renderablePosts + mapM_ (renderChain ["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 + renderRss myFeedConfiguration $ + map (>>> copyValue "body" "description") (take 3 renderablePosts) - where postManipulation :: ContextManipulation - postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" - . renderTagLinks tagToUrl + where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" + >>> renderTagLinks tagToUrl tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html" renderPostList url title posts = do - let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)] + let list = createListing url ["templates/postitem.html"] posts [("title", Left title)] renderChain ["posts.html", "templates/default.html"] list + +myFeedConfiguration = FeedConfiguration + { feedUrl = "rss.xml" + , feedTitle = "SimpleBlog RSS feed." + , feedDescription = "A simple demo of an RSS feed created with Hakyll." + , feedAuthorName = "Jasper Van der Jeugt" + } -- cgit v1.2.3