on master help sign in
Updated tagblog example to hakyll-2.x
4e6ab05Jasper Van der Jeugt
examples/tagblog/hakyll.hs+32−25
@@ -1,60 +1,67 @@
1module Main where
1module Main where
2
2
3+import Control.Arrow ((>>>))
3import Text.Hakyll (hakyll)
4import Text.Hakyll (hakyll)
4import Text.Hakyll.Render
5import 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)
6import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
8import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
7−import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListingWith, createListing)
9+import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
8−import Text.Hakyll.Context (ContextManipulation, renderDate)
10+import Text.Hakyll.ContextManipulations (renderDate, copyValue)
9import Data.List (sort)
11import Data.List (sort)
10import Data.Map (toList)
12import Data.Map (toList)
11import Control.Monad (mapM_, liftM)
13import Control.Monad (mapM_, liftM)
12import Data.Either (Either(..))
14import Data.Either (Either(..))
13
15
14−main = hakyll $ do
16+main = hakyll "http://example.com" $ do
15 -- Static directory.
17 -- Static directory.
16 directory css "css"
18 directory css "css"
17
19
18 -- Find all post paths.
20 -- Find all post paths.
19 postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
21 postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
20− let renderablePosts = map createPagePath postPaths
22+ let renderablePosts = map ((>>> postManipulation) . createPage) postPaths
21
23
22 -- Read tag map.
24 -- Read tag map.
23− tagMap <- readTagMap "postTags" renderablePosts
25+ let tagMap = readTagMap "postTags" postPaths
24
26
25 -- Render all posts list.
27 -- Render all posts list.
26 renderPostList "posts.html" "All posts" renderablePosts
28 renderPostList "posts.html" "All posts" renderablePosts
27
29
28 -- Render post list per tag
30 -- Render post list per tag
31+ withTagMap tagMap $ \tag posts ->
29− mapM_ (\(tag, posts) -> renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) posts)
32+ renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) (map (>>> postManipulation) posts)
30− (toList tagMap)
31
33
32 -- Render index, including recent posts.
34 -- Render index, including recent posts.
33− let tagCloud = renderTagCloud tagMap tagToUrl 100 200
35+ let tagCloud = tagMap >>> renderTagCloud tagToUrl 100 200
34− index = createListingWith postManipulation "index.html"
36+ index = createListing "index.html"
35− "templates/postitem.html"
37+ ["templates/postitem.html"]
36− (take 3 renderablePosts)
38+ (take 3 renderablePosts)
37− [ ("title", "Home")
39+ [ ("title", Left "Home")
38− , ("tagcloud", tagCloud)
40+ , ("tagcloud", Right tagCloud)
39− ]
41+ ]
40 renderChain ["index.html", "templates/default.html"] index
42 renderChain ["index.html", "templates/default.html"] index
41
43
42 -- Render all posts.
44 -- Render all posts.
43− mapM_ (renderChainWith postManipulation
44− ["templates/post.html"
45+ mapM_ (renderChain ["templates/post.html"
45− ,"templates/default.html"
46+ ,"templates/default.html"
46− ]) renderablePosts
47+ ]) renderablePosts
47
48
48 -- Render rss feed
49 -- Render rss feed
49− let rss = createListing "rss.xml" "templates/rssitem.xml" (take 3 renderablePosts) []
50+ renderRss myFeedConfiguration $
50− renderChain ["templates/rss.xml"] rss
51+ map (>>> copyValue "body" "description") (take 3 renderablePosts)
51
52
52− where postManipulation :: ContextManipulation
53− postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
53+ where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
54− . renderTagLinks tagToUrl
54+ >>> renderTagLinks tagToUrl
55
55
56 tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
56 tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
57
57
58 renderPostList url title posts = do
58 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)]
60 renderChain ["posts.html", "templates/default.html"] list
60 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+ }
examples/tagblog/templates/rss.xmldeleted−9
@@ -1,9 +0,0 @@
1−<?xml version="1.0" ?>
2−<rss version="2.0">
3− <channel>
4− <title>The SimpleBlog</title>
5− <link>http://example.com</link>
6− <description>Simple blog in hakyll</description>
7− $body
8− </channel>
9−</rss>
examples/tagblog/templates/rssitem.xmldeleted−5
@@ -1,5 +0,0 @@
1−<item>
2− <title>$title</title>
3− <link>http://example.com/$url</link>
4− <description>$title by $author</description>
5−</item>