on master help sign in
Updated simpleblog, rssblog and tagblog examples to trunk.
7128cc9Jasper Van der Jeugt
examples/rssblog/hakyll.hs+7−14
@@ -4,7 +4,7 @@ import Control.Monad.Reader (liftIO)
4import Text.Hakyll (hakyll)
4import Text.Hakyll (hakyll)
5import Text.Hakyll.Render (renderAndConcat, renderChain, css)
5import Text.Hakyll.Render (renderAndConcat, renderChain, css)
6import Text.Hakyll.File (getRecursiveContents, directory)
6import Text.Hakyll.File (getRecursiveContents, directory)
7−import Text.Hakyll.Renderables (createPagePath, createCustomPage)
7+import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListing)
8import Data.List (sort)
8import Data.List (sort)
9import Control.Monad (mapM_, liftM)
9import Control.Monad (mapM_, liftM)
10import Data.Either (Either(..))
10import Data.Either (Either(..))
@@ -18,24 +18,17 @@ main = hakyll $ do
18 let renderablePosts = map createPagePath postPaths
18 let renderablePosts = map createPagePath postPaths
19
19
20 -- Render index, including recent posts.
20 -- Render index, including recent posts.
21− let recentPosts = renderAndConcat ["templates/postitem.html"] $ take 3 renderablePosts
21+ let index = createListing "index.html" "templates/postitem.html" (take 3 renderablePosts) [("title", "Home")]
22− renderChain ["index.html", "templates/default.html"] $
22+ renderChain ["index.html", "templates/default.html"] index
23− createCustomPage "index.html" ("templates/postitem.html" : take 3 postPaths)
24− [("title", Left "Home"), ("posts", Right recentPosts)]
25
23
26 -- Render all posts list.
24 -- Render all posts list.
27− let postItems = renderAndConcat ["templates/postitem.html"] $ renderablePosts
25+ let posts = createListing "posts.html" "templates/postitem.html" renderablePosts [("title", "All posts")]
28− renderChain ["posts.html", "templates/default.html"] $
26+ renderChain ["posts.html", "templates/default.html"] posts
29− createCustomPage "posts.html" ("templates/postitem.html" : postPaths)
30− [("title", Left "All posts"), ("posts", Right postItems)]
31
27
32 -- Render all posts.
28 -- Render all posts.
33 liftIO $ putStrLn "Generating posts..."
29 liftIO $ putStrLn "Generating posts..."
34 mapM_ (renderChain ["templates/post.html", "templates/default.html"]) renderablePosts
30 mapM_ (renderChain ["templates/post.html", "templates/default.html"]) renderablePosts
35
31
36 -- Render rss feed
32 -- Render rss feed
37− let recentRSSItems = renderAndConcat ["templates/rssitem.xml"] $ take 3 renderablePosts
33+ let rss = createListing "rss.xml" "templates/rssitem.xml" (take 3 renderablePosts) []
38− let rssPage = createCustomPage "rss.xml"
39− ("templates/postitem.html" : take 3 postPaths)
40− [("items", Right recentRSSItems)]
41− renderChain ["templates/rss.xml"] rssPage
34+ renderChain ["templates/rss.xml"] rss
examples/rssblog/index.html+1−1
@@ -1,7 +1,7 @@
1<div id="posts">
1<div id="posts">
2 <h1>Recent posts</h1>
2 <h1>Recent posts</h1>
3 <ul>
3 <ul>
4− $posts
4+ $body
5 </ul>
5 </ul>
6 <a href="$root/posts.html">All posts...</a>
6 <a href="$root/posts.html">All posts...</a>
7</div>
7</div>
examples/rssblog/posts.html+1−1
@@ -1,4 +1,4 @@
1<h1>All posts</h1>
1<h1>All posts</h1>
2<ul>
2<ul>
3− $posts
3+ $body
4</ul>
4</ul>
examples/rssblog/templates/rss.xml+1−1
@@ -4,6 +4,6 @@
4 <title>The SimpleBlog</title>
4 <title>The SimpleBlog</title>
5 <link>http://example.com</link>
5 <link>http://example.com</link>
6 <description>Simple blog in hakyll</description>
6 <description>Simple blog in hakyll</description>
7− $items
7+ $body
8 </channel>
8 </channel>
9</rss>
9</rss>
examples/simpleblog/hakyll.hs+4−4
@@ -19,12 +19,12 @@ main = hakyll $ do
19 let renderablePosts = map createPagePath postPaths
19 let renderablePosts = map createPagePath postPaths
20
20
21 -- Render index, including recent posts.
21 -- Render index, including recent posts.
22− renderChain ["index.html", "templates/default.html"] $
23− createListing "index.html" "templates/postitem.html" (take 3 renderablePosts) [("title", "Home")]
22+ let index = createListing "index.html" "templates/postitem.html" (take 3 renderablePosts) [("title", "Home")]
23+ renderChain ["index.html", "templates/default.html"] index
24
24
25 -- Render all posts list.
25 -- Render all posts list.
26− renderChain ["posts.html", "templates/default.html"] $
27− createListing "posts.html" "templates/postitem.html" renderablePosts [("title", "All posts")]
26+ let posts = createListing "posts.html" "templates/postitem.html" renderablePosts [("title", "All posts")]
27+ renderChain ["posts.html", "templates/default.html"] posts
28
28
29 -- Render all posts.
29 -- Render all posts.
30 liftIO $ putStrLn "Generating posts..."
30 liftIO $ putStrLn "Generating posts..."
examples/tagblog/hakyll.hs+13−17
@@ -4,7 +4,7 @@ import Text.Hakyll (hakyll)
4import Text.Hakyll.Render
4import Text.Hakyll.Render
5import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks)
5import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks)
6import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
6import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
7−import Text.Hakyll.Renderables (createPagePath, createCustomPage)
7+import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListingWith)
8import Text.Hakyll.Context (ContextManipulation, renderDate)
8import Text.Hakyll.Context (ContextManipulation, renderDate)
9import Data.List (sort)
9import Data.List (sort)
10import Data.Map (toList)
10import Data.Map (toList)
@@ -20,23 +20,24 @@ main = hakyll $ do
20 let renderablePosts = map createPagePath postPaths
20 let renderablePosts = map createPagePath postPaths
21
21
22 -- Read tag map.
22 -- Read tag map.
23− tagMap <- readTagMap "postTags" postPaths
23+ tagMap <- readTagMap "postTags" renderablePosts
24
24
25 -- Render all posts list.
25 -- Render all posts list.
26− renderPostList "posts.html" "All posts" postPaths
26+ renderPostList "posts.html" "All posts" renderablePosts
27
27
28 -- Render post list per tag
28 -- Render post list per tag
29 mapM_ (\(tag, posts) -> renderPostList (tagToURL tag) ("Posts tagged " ++ tag) posts)
29 mapM_ (\(tag, posts) -> renderPostList (tagToURL tag) ("Posts tagged " ++ tag) posts)
30 (toList tagMap)
30 (toList tagMap)
31
31
32 -- Render index, including recent posts.
32 -- Render index, including recent posts.
33− let recentPosts = renderAndConcatWith postManipulation
34− ["templates/postitem.html"]
35− (take 3 renderablePosts)
36− renderChain ["index.html", "templates/default.html"] $
37− createCustomPage "index.html" ("templates/postitem.html" : take 3 postPaths)
38− [("title", Left "Home"), ("posts", Right recentPosts),
39− ("tagcloud", Left $ renderTagCloud tagMap tagToURL 100 200)]
33+ let tagCloud = renderTagCloud tagMap tagToURL 100 200
34+ let index = createListingWith postManipulation "index.html"
35+ "templates/postitem.html"
36+ (take 3 renderablePosts)
37+ [ ("title", "Home")
38+ , ("tagcloud", tagCloud)
39+ ]
40+ renderChain ["index.html", "templates/default.html"] index
40
41
41 -- Render all posts.
42 -- Render all posts.
42 mapM_ (renderChainWith postManipulation
43 mapM_ (renderChainWith postManipulation
@@ -61,10 +62,5 @@ main = hakyll $ do
61 tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
62 tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
62
63
63 renderPostList url title posts = do
64 renderPostList url title posts = do
64− let postItems = renderAndConcatWith postManipulation
65− ["templates/postitem.html"]
66− (map createPagePath posts)
67− customPage = createCustomPage url
68− ("templates/postitem.html" : posts)
65+ let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)]
69− [("title", Left title), ("posts", Right postItems)]
70− renderChain ["posts.html", "templates/default.html"] customPage
66+ renderChain ["posts.html", "templates/default.html"] list
examples/tagblog/index.html+1−1
@@ -1,7 +1,7 @@
1<div id="posts">
1<div id="posts">
2 <h1>Recent posts</h1>
2 <h1>Recent posts</h1>
3 <ul>
3 <ul>
4− $posts
4+ $body
5 </ul>
5 </ul>
6 <a href="$root/posts.html">All posts...</a>
6 <a href="$root/posts.html">All posts...</a>
7 <div>
7 <div>
examples/tagblog/posts.html+1−1
@@ -1,4 +1,4 @@
1<h1>$title</h1>
1<h1>$title</h1>
2<ul>
2<ul>
3− $posts
3+ $body
4</ul>
4</ul>