@@ -1,60 +1,67 @@
11module Main where
22
3+import Control.Arrow ((>>>))
34import Text.Hakyll (hakyll)
45import Text.Hakyll.Render
5−import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks)
6+import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks, withTagMap)
7+import Text.Hakyll.Feed (FeedConfiguration (..), renderRss)
68import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
7−import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListingWith, createListing)
8−import Text.Hakyll.Context (ContextManipulation, renderDate)
9+import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
10+import Text.Hakyll.ContextManipulations (renderDate, copyValue)
911import Data.List (sort)
1012import Data.Map (toList)
1113import Control.Monad (mapM_, liftM)
1214import Data.Either (Either(..))
1315
14−main = hakyll $ do
16+main = hakyll "http://example.com" $ do
1517 -- Static directory.
1618 directory css "css"
1719
1820 -- Find all post paths.
1921 postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
20− let renderablePosts = map createPagePath postPaths
22+ let renderablePosts = map ((>>> postManipulation) . createPage) postPaths
2123
2224 -- Read tag map.
23− tagMap <- readTagMap "postTags" renderablePosts
25+ let tagMap = readTagMap "postTags" postPaths
2426
2527 -- Render all posts list.
2628 renderPostList "posts.html" "All posts" renderablePosts
2729
2830 -- Render post list per tag
29− mapM_ (\(tag, posts) -> renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) posts)
30− (toList tagMap)
31+ withTagMap tagMap $ \tag posts ->
32+ renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) (map (>>> postManipulation) posts)
3133
3234 -- Render index, including recent posts.
33− let tagCloud = renderTagCloud tagMap tagToUrl 100 200
34− index = createListingWith postManipulation "index.html"
35− "templates/postitem.html"
36− (take 3 renderablePosts)
37− [ ("title", "Home")
38− , ("tagcloud", tagCloud)
39− ]
35+ let tagCloud = tagMap >>> renderTagCloud tagToUrl 100 200
36+ index = createListing "index.html"
37+ ["templates/postitem.html"]
38+ (take 3 renderablePosts)
39+ [ ("title", Left "Home")
40+ , ("tagcloud", Right tagCloud)
41+ ]
4042 renderChain ["index.html", "templates/default.html"] index
4143
4244 -- Render all posts.
43− mapM_ (renderChainWith postManipulation
44− ["templates/post.html"
45− ,"templates/default.html"
46− ]) renderablePosts
45+ mapM_ (renderChain ["templates/post.html"
46+ ,"templates/default.html"
47+ ]) renderablePosts
4748
4849 -- Render rss feed
49− let rss = createListing "rss.xml" "templates/rssitem.xml" (take 3 renderablePosts) []
50− renderChain ["templates/rss.xml"] rss
50+ renderRss myFeedConfiguration $
51+ map (>>> copyValue "body" "description") (take 3 renderablePosts)
5152
52− where postManipulation :: ContextManipulation
53− postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
54− . renderTagLinks tagToUrl
53+ where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
54+ >>> renderTagLinks tagToUrl
5555
5656 tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
5757
5858 renderPostList url title posts = do
59− let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)]
59+ let list = createListing url ["templates/postitem.html"] posts [("title", Left title)]
6060 renderChain ["posts.html", "templates/default.html"] list
61+
62+myFeedConfiguration = FeedConfiguration
63+ { feedUrl = "rss.xml"
64+ , feedTitle = "SimpleBlog RSS feed."
65+ , feedDescription = "A simple demo of an RSS feed created with Hakyll."
66+ , feedAuthorName = "Jasper Van der Jeugt"
67+ }