@@ -0,0 +1,64 @@
1+module Main where
2+
3+import Text.Hakyll (hakyll)
4+import Text.Hakyll.Render
5+import Text.Hakyll.Tags (readCategoryMap)
6+import 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.Util (link)
10+import Data.List (sort)
11+import Data.Map (toList)
12+import Control.Monad (mapM_, liftM, (<=<))
13+import Data.Either (Either(..))
14+
15+main = hakyll $ do
16+ -- Static directory.
17+ directory css "css"
18+
19+ -- Find all post paths.
20+ postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
21+ let renderablePosts = map createPagePath postPaths
22+
23+ -- Read category map.
24+ categoryMap <- readCategoryMap "categoryMap" renderablePosts
25+
26+ -- Render all posts list.
27+ renderPostList "posts.html" "All posts" renderablePosts
28+
29+ -- Render post list per category
30+ mapM_ (\(category, posts) -> renderPostList (categoryToURL category) ("Posts about " ++ category) posts)
31+ (toList categoryMap)
32+
33+ -- Render index, including recent posts.
34+ let index = createListingWith postManipulation "index.html"
35+ "templates/postitem.html"
36+ (take 3 renderablePosts)
37+ [ ("title", "Home")
38+ , ("categories", categoryList categoryMap)
39+ ]
40+ renderChain ["index.html", "templates/default.html"] index
41+
42+ -- Render all posts.
43+ mapM_ (renderChainWith postManipulation
44+ ["templates/post.html"
45+ ,"templates/default.html"
46+ ]) renderablePosts
47+
48+ -- Render rss feed
49+ let rss = createListing "rss.xml" "templates/rssitem.xml" (take 3 renderablePosts) []
50+ renderChain ["templates/rss.xml"] rss
51+
52+ where postManipulation :: ContextManipulation
53+ postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
54+
55+ categoryToURL category = "$root/categories/" ++ removeSpaces category ++ ".html"
56+
57+ categoryList = uncurry categoryListItem <=< toList
58+
59+ categoryListItem category posts = "<li>" ++ link category (categoryToURL category)
60+ ++ " - " ++ show (length posts) ++ " items.</li>"
61+
62+ renderPostList url title posts = do
63+ let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)]
64+ renderChain ["posts.html", "templates/default.html"] list