diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-03-21 15:57:12 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-03-21 15:57:12 +0100 |
commit | 4e6ab05b7803833d07e502797ad28c908f7d14d2 (patch) | |
tree | 9b08ef9de146fef8847b197322fecdc3bb338386 /examples/tagblog/hakyll.hs | |
parent | 099de3b47f849307abc8c83d7b87fa4d46ea6c6c (diff) | |
download | hakyll-4e6ab05b7803833d07e502797ad28c908f7d14d2.tar.gz |
Updated tagblog example to hakyll-2.x
Diffstat (limited to 'examples/tagblog/hakyll.hs')
-rw-r--r-- | examples/tagblog/hakyll.hs | 57 |
1 files changed, 32 insertions, 25 deletions
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" + } |