@@ -0,0 +1,69 @@
1+module Main where
2+
3+import Text.Hakyll (hakyll)
4+import Text.Hakyll.Render
5+import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks)
6+import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
7+import Text.Hakyll.Renderables (createPagePath, createCustomPage)
8+import Text.Hakyll.Context (ContextManipulation, renderDate)
9+import Data.List (sort)
10+import Data.Map (toList)
11+import Control.Monad (mapM_, liftM)
12+import Data.Either (Either(..))
13+
14+main = hakyll $ do
15+ -- Static directory.
16+ directory css "css"
17+
18+ -- Find all post paths.
19+ postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
20+ let renderablePosts = map createPagePath postPaths
21+
22+ -- Read tag map.
23+ tagMap <- readTagMap postPaths
24+
25+ -- Render all posts list.
26+ renderPostList "posts.html" "All posts" postPaths
27+
28+ -- Render post list per tag
29+ mapM_ (\(tag, posts) -> renderPostList (tagToURL tag) ("Posts tagged " ++ tag) posts)
30+ (toList tagMap)
31+
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+
40+ -- Render all posts.
41+ mapM_ (renderChainWith postManipulation
42+ ["templates/post.html"
43+ ,"templates/default.html"
44+ ]) renderablePosts
45+
46+ -- Render rss feed
47+ let recentRSSItems = renderAndConcat "templates/rssitem.xml" $ take 3 renderablePosts
48+ let rssPage = createCustomPage "rss.xml"
49+ ("templates/postitem.html" : take 3 postPaths)
50+ [("items", Right recentRSSItems)]
51+ renderChain ["templates/rss.xml"] rssPage
52+
53+ -- Render index.
54+ renderChain ["templates/default.html"] $ createPagePath "index.html"
55+
56+ where postManipulation :: ContextManipulation
57+ postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
58+ . renderTagLinks tagToURL
59+
60+ tagToURL tag = "/tags/" ++ removeSpaces tag ++ ".html"
61+
62+ renderPostList url title posts = do
63+ let postItems = renderAndConcatWith postManipulation
64+ "templates/postitem.html"
65+ (map createPagePath posts)
66+ customPage = createCustomPage url
67+ ("templates/postitem.html" : posts)
68+ [("title", Left title), ("posts", Right postItems)]
69+ renderChain ["posts.html", "templates/default.html"] customPage