on master help sign in
Adapted examples to general style guide.

Because I thought the examples should follow the same style guidelines as the Hakyll code itself, I adapted them to it.

commit622c259708503eb9eb766fe0b00c28b979e2e653 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 30 Mar 2010, 19:25 (17 years ago) parent82931dd
5 files changed+55−39
examples/brochure/hakyll.hs+3−2 examples/categoryblog/hakyll.hs+20−15 examples/feedblog/hakyll.hs+8−4 examples/simpleblog/hakyll.hs+8−5 examples/tagblog/hakyll.hs+16−13
examples/brochure/hakyll.hs+3−2
@@ -8,5 +8,6 @@ main = hakyll "http://example.com" $ do
88 render "about.rst"
99 render "index.markdown"
1010 render "code.lhs"
11− where render = renderChain ["templates/default.html"]
12− . createPage
11+ where
12+ render = renderChain ["templates/default.html"]
13+ . createPage
examples/categoryblog/hakyll.hs+20−15
@@ -10,7 +10,7 @@ import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
1010import Text.Hakyll.ContextManipulations (renderDate, copyValue, changeValue)
1111import Text.Hakyll.Util (link)
1212import Data.Map (toList)
13−import Control.Monad (mapM_, liftM, (<=<))
13+import Control.Monad (forM_, liftM, (<=<))
1414import Data.Either (Either(..))
1515
1616main = hakyll "http://example.com" $ do
@@ -34,38 +34,43 @@ main = hakyll "http://example.com" $ do
3434 withTagMap categoryMap renderListForCategory
3535
3636 -- Render index, including recent posts.
37+ let categoryList' = categoryMap >>> categoryList
3738 let index = createListing "index.html"
3839 ["templates/postitem.html"]
3940 (take 3 renderablePosts)
4041 [ ("title", Left "Home")
41− , ("categories", Right $ categoryMap >>> categoryList)
42+ , ("categories", Right $ categoryList')
4243 ]
4344 renderChain ["index.html", "templates/default.html"] index
4445
4546 -- Render all posts.
46− mapM_ (renderChain ["templates/post.html"
47− ,"templates/default.html"
48− ]) renderablePosts
47+ forM_ renderablePosts $ renderChain [ "templates/post.html"
48+ , "templates/default.html"
49+ ]
4950
5051 -- Render rss feed
5152 renderRss myFeedConfiguration $
5253 map (>>> copyValue "body" "description") (take 3 renderablePosts)
5354
54− where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
55− >>> renderCategoryLink
55+ where
56+ postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
57+ >>> renderCategoryLink
5658
57− renderCategoryLink = changeValue "category" (\c -> link c $ categoryToUrl c)
59+ renderCategoryLink =
60+ changeValue "category" (\c -> link c $ categoryToUrl c)
5861
59− categoryToUrl category = "$root/categories/" ++ removeSpaces category ++ ".html"
62+ categoryToUrl c = "$root/categories/" ++ removeSpaces c ++ ".html"
6063
61− categoryList = arr $ uncurry categoryListItem <=< toList
64+ categoryList = arr $ uncurry categoryListItem <=< toList
6265
63− categoryListItem category posts = "<li>" ++ link category (categoryToUrl category)
64− ++ " - " ++ show (length posts) ++ " items.</li>"
66+ categoryListItem category posts =
67+ "<li>" ++ link category (categoryToUrl category)
68+ ++ " - " ++ show (length posts) ++ " items.</li>"
6569
66− renderPostList url title posts = do
67− let list = createListing url ["templates/postitem.html"] posts [("title", Left title)]
68− renderChain ["posts.html", "templates/default.html"] list
70+ renderPostList url title posts = do
71+ let list = createListing url ["templates/postitem.html"]
72+ posts [("title", Left title)]
73+ renderChain ["posts.html", "templates/default.html"] list
6974
7075myFeedConfiguration = FeedConfiguration
7176 { feedUrl = "rss.xml"
examples/feedblog/hakyll.hs+8−4
@@ -9,7 +9,7 @@ import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
99import Text.Hakyll.ContextManipulations (copyValue)
1010import Text.Hakyll.Feed (FeedConfiguration (..), renderRss)
1111import Data.List (sort)
12−import Control.Monad (mapM_, liftM)
12+import Control.Monad (forM_, liftM)
1313import Control.Monad.Reader (liftIO)
1414import Data.Either (Either(..))
1515
@@ -22,16 +22,20 @@ main = hakyll "http://example.com" $ do
2222 let postPages = map createPage postPaths
2323
2424 -- Render index, including recent posts.
25− let index = createListing "index.html" ["templates/postitem.html"] (take 3 postPages) [("title", Left "Home")]
25+ let index = createListing "index.html" ["templates/postitem.html"]
26+ (take 3 postPages) [("title", Left "Home")]
2627 renderChain ["index.html", "templates/default.html"] index
2728
2829 -- Render all posts list.
29− let posts = createListing "posts.html" ["templates/postitem.html"] postPages [("title", Left "All posts")]
30+ let posts = createListing "posts.html" ["templates/postitem.html"]
31+ postPages [("title", Left "All posts")]
3032 renderChain ["posts.html", "templates/default.html"] posts
3133
3234 -- Render all posts.
3335 liftIO $ putStrLn "Generating posts..."
34− mapM_ (renderChain ["templates/post.html", "templates/default.html"]) postPages
36+ forM_ postPages $ renderChain [ "templates/post.html"
37+ , "templates/default.html"
38+ ]
3539
3640 -- Render RSS feed.
3741 renderRss myFeedConfiguration $
examples/simpleblog/hakyll.hs+8−5
@@ -6,7 +6,7 @@ import Text.Hakyll.Context
66import Text.Hakyll.File (getRecursiveContents, directory)
77import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
88import Data.List (sort)
9−import Control.Monad (mapM_, liftM)
9+import Control.Monad (forM_, liftM)
1010import Control.Monad.Reader (liftIO)
1111import Data.Either (Either(..))
1212
@@ -19,14 +19,17 @@ main = hakyll "http://example.com" $ do
1919 let postPages = map createPage postPaths
2020
2121 -- Render index, including recent posts.
22− let index = createListing "index.html" ["templates/postitem.html"] (take 3 postPages) [("title", Left "Home")]
22+ let index = createListing "index.html" ["templates/postitem.html"]
23+ (take 3 postPages) [("title", Left "Home")]
2324 renderChain ["index.html", "templates/default.html"] index
2425
2526 -- Render all posts list.
26− let posts = createListing "posts.html" ["templates/postitem.html"] postPages [("title", Left "All posts")]
27+ let posts = createListing "posts.html" ["templates/postitem.html"]
28+ postPages [("title", Left "All posts")]
2729 renderChain ["posts.html", "templates/default.html"] posts
2830
2931 -- Render all posts.
3032 liftIO $ putStrLn "Generating posts..."
31− mapM_ (renderChain ["templates/post.html", "templates/default.html"]) postPages
32−
33+ forM_ postPages $ renderChain [ "templates/post.html"
34+ , "templates/default.html"
35+ ]
examples/tagblog/hakyll.hs+16−13
@@ -10,7 +10,7 @@ import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
1010import Text.Hakyll.ContextManipulations (renderDate, copyValue)
1111import Data.List (sort)
1212import Data.Map (toList)
13−import Control.Monad (mapM_, liftM)
13+import Control.Monad (forM_, liftM)
1414import Data.Either (Either(..))
1515
1616main = hakyll "http://example.com" $ do
@@ -28,9 +28,10 @@ main = hakyll "http://example.com" $ do
2828 renderPostList "posts.html" "All posts" renderablePosts
2929
3030 -- Render post list per tag
31− let renderListForTag tag posts = renderPostList (tagToUrl tag) ("Posts tagged " ++ tag)
32− (map (>>> postManipulation) posts)
33− withTagMap tagMap renderPostList
31+ let renderListForTag tag posts =
32+ renderPostList (tagToUrl tag) ("Posts tagged " ++ tag)
33+ (map (>>> postManipulation) posts)
34+ withTagMap tagMap renderListForTag
3435
3536 -- Render index, including recent posts.
3637 let tagCloud = tagMap >>> renderTagCloud tagToUrl 100 200
@@ -43,22 +44,24 @@ main = hakyll "http://example.com" $ do
4344 renderChain ["index.html", "templates/default.html"] index
4445
4546 -- Render all posts.
46− mapM_ (renderChain ["templates/post.html"
47− ,"templates/default.html"
48− ]) renderablePosts
47+ forM_ renderablePosts $ renderChain [ "templates/post.html"
48+ , "templates/default.html"
49+ ]
4950
5051 -- Render rss feed
5152 renderRss myFeedConfiguration $
5253 map (>>> copyValue "body" "description") (take 3 renderablePosts)
5354
54− where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
55− >>> renderTagLinks tagToUrl
55+ where
56+ postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
57+ >>> renderTagLinks tagToUrl
5658
57− tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
59+ tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
5860
59− renderPostList url title posts = do
60− let list = createListing url ["templates/postitem.html"] posts [("title", Left title)]
61− renderChain ["posts.html", "templates/default.html"] list
61+ renderPostList url title posts = do
62+ let list = createListing url ["templates/postitem.html"]
63+ posts [("title", Left title)]
64+ renderChain ["posts.html", "templates/default.html"] list
6265
6366myFeedConfiguration = FeedConfiguration
6467 { feedUrl = "rss.xml"